mysql system command - mysql

I am in MySQL and would like to change the current working directory. I tried to execute:
mysql> system cd './my_dir'
However, this does not seem to work. Has anyone run into a similar problem?

System is going to spawn a child process to run a shell command.....
Current working directory is a process level property....so you can't change it in the parent from a child process. That's why it doesn't work.
I briefly scanned the MySQL docs at http://dev.mysql.com/doc/refman/5.5/en/mysql-commands.html but didn't see a direct CD command that changes the working directory. I think an adventurous person could write one....

If you want to change your current working directory for a script, then use the && between the CD and script so it will change directory and then if that's successful it will execute the second command.
mysql> SYSTEM cd /home && ls

What you're looking for is the escape to shell command: \!
mysql>\! cd ./my_dir
You can even use it to escape to the shell completely and then come back to the mysql environment.
mysql>\! bash
bash>cd ./my_dir
bash>exit
mysql>SELECT * ALL FROM <table>;

Related

PHP Mysql laravel 5.4 terminal issue

i am new to laravel i just figured out how to install composer laravel etc etc on my local machine MAMP on windows , Now i am confuse with the command on terminal which is
C:\project>mysql -uroot -proot
'mysql' is not recognized as an internal or external command,
operable program or batch file.
How can i fix this ?
setting Environment will solve the issue
Go to Control Panel -> System -> Advanced
Click - Environment Variables
Go to- System Variables find PATH and click on it.
add the path to your mysql\bin folder to the end paths. (ex: E:\xampp\mysql\bin) and add ; end of the line
Close all the command prompts you opens.
Re open and try it.
Setting the PATH to point to the MYSQL bin folder is normally the first thought, but I find that dangerous as things get left lying around when you change software.
I normally create a little batch file in the projects folder or in a folder that it already on your PATH, like this
mysqlpath.cmd
echo off
PATH=C:\mamp\path\to\the\mysql\bin;%PATH%
mysql -v
The mysql -v will output the mysql version number but it is a handy way of knowing that the correct folder has been added to the PATH. This adds the folder to the PATH but only for the life of the command window.
Then just run this from any command window when you want to use MYSQL from the command line
> phppath
You may also like to create one for PHP as well
phppath.cmd
echo off
PATH=C:\mamp\path\to\the\php\;%PATH%
php -v

cron tab to execute rails commands

i am running a cron tab for every 5 minutes,it contains an .sh files which need to be executed ,where that .sh file consists of ruby code....one thing i can't understand that when i am executing the .sh file directly in terminal its get execute,but the same thing in crontab fails..my entry in crontab follows :
1) mysqldump -uroot -p'myPassword' redmine144 > redmine144_$(date +%Y_%m_%d_%H_%M).sql;
2) cd /home/ror/Projects/redmine144/;
source /usr/local/rvm/environments/ruby-1.9.3-p194#redmine144
bundle exec rake "hb:project_progress"
First one to take backup and it is working fine.
Second one to run some ruby rake task(not working form cron tab)
usually crontab output in not directed to stdout so you check your out put in /var/log/cron file which contains the cron logs. you can add the output and redirect the error, for more see http://www.thegeekstuff.com/2012/07/crontab-log/ and check what error pops upp and you'll be able to figure it out...
Making RVM work with cron is really tricky. I'll share a snippet from my own crontab that is proven to work (with system-wide RVM) - just make sure your app path has a .rvmrc specifying the ruby version and gemset.
MAILTO=mymail#gmail.com
SHELL=/bin/bash
? ? ? ? ? source /etc/profile.d/rvm.sh; cd /app/home/path && bundle exec rake whatever_you_need RAILS_ENV=production
SHELL is important.
The MAILTO is there to aid debugging and could be removed later.
Don't forget to substitute your schedule for the question marks.

Retrieve lost file using Vi in MySQL

I would like to know how to retrieve a file using Vi in MySQL. I logged in using:
mysql -uuser -p -hserver -A database
Then I do:
\e
The editor opens and I type my query of 200 lines, then I :wq and \G (if I save the file it says: /tmp/sql9SbYQZ saved) and I see the result.
Now, if I make a mistake or run a different query and I try to type \e again, the query is lost.
ll /tmp/sql9SbYQZ
ls: /tmp/sql9SbYQZ: No such file or directory
Is there a way to retrieve the lost file?
Here's what I added to my .vimrc in order to save the current query in case i made a mistake.
nmap <F7> :w! /tmp/query.sql\| wq!<CR>
This will create a map to the F7 key (you can change it of course). So every time you open a file either using edit or \e, you change it use the F7 key.
This will save a backup of your current query to /tmp/query.sql and then save and close the temporary file. This way, if you make a mistake, you just re-open the backup file and try again.
Here's also a link you might like: http://vim.wikia.com/wiki/Open_the_last_edited_file
With the vi/m editor used with mysql, crontab, and many others, the work is done in a tmp file, as you see from your messages.
Edit (Big doah!, remove cruft about ls -l /tmp/..., you already did that!)
In the future the solution is to tell vim to w the buffer to a file name of your chosing, i.e.
w! /home/you/scripts/mysql2.sql
Then close the editor with
q
Note you may not need the ! after w.
I hope this helps.
Here is something you can try:
In Linux, do the following
$ cd
$ cp .mysql_history mystuff.txt
$ vi mystuff.txt
You should see the file .mysql_history. The mysql client records all queries and commands executed. Hopefully, your query is in there.
Give it a Try !!!

How do I get Hudson to stop escaping parts of my shell script?

I would like to have a shell script that copies some logs from a part of my system to the hudson workspace so I can archive them.
So right now I have
#!/bin/bash -ex
cp /directory/structure/*.log .
This is kind enough to be changed to
cp '/directory/structure/*.log' .
Which of course is not found since I don't have a file named *.log.
So how do I get this script to work?
EDIT
So I left out the part that I was using sudo cp /path/*.log, because I didn't think that would matter. Of course it does and sudo is the issue not hudson.
One simple answer would be to have the shell script in a separate file, and have hudson call that.
sudo bash -c "cp /directory/structure/*.log"
Throwing it out there, but haven't had a chance to try it in Hudson (so I don't know how it gets quoted):
for f in /directory/structure/*.log ; do
cp $f .
done
In my simple test in a bash shell, different quoting options produce either one or multiple invocations of the copy command (either with all matching files or one at a time), but they all manage to do the copy successfully.

How to install MySQL on Leopard, Mac OS X 10.5?

I followed this tutorial to the very end, then found out it didn't work right. I think I have everything installed but when I type
mysql -uroot
I only get
-bash: mysql: command not found
Note: I did not skip the "Setting the Path" step. Upon running this command for the first time:
mate ~/.bash_login
This brought up an empty file. So I added this line:
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
I saved the file, closed TextMate, executed the following command:
. ~/.bash_login
...and continued with the tutorial. Based on your suggestions, I thought maybe the file didn't actually get saved. So I ran the following command to bring up the file again:
mate ~/.bash_login
...yet the contents of the file were as they should be.
Any suggestions?
You probably don't have the mysql binaries in your path.
The link you posted has a section on setting the path, titled "Setting the Path Do not skip this step! Most everything else will fail if you do."
EDIT: As debugging steps, try:
First launching a new terminal window. Does it run now?
Typing "echo $PATH" at the prompt. Does the path show up correctly as you've typed it in bash_profile?
Running it the long way: /usr/local/mysql/bin/mysql -u root
Does the application run?
Did you follow the step that says
Setting the Path
Do not skip this step! Most everything
else will fail if you do.
Did you close your terminal window and re-open it afterwards?
Update:
What does "which mysql" say? Does "ls /usr/local/mysql/bin" say?
Two things:
Try editing ~/.profile (rather than ~/.bash_profile or ~/.bash_login).
You may find it easier to use the native Mac style .dmg installer directly from Sun.
One nice thing about the dmg installer is that it automagically sets up symlinks to /usr/local/mysql (which means less - or no - fiddling with your $PATH).
Another option would be to use MAMP.
It has Apache, PHP and MySQL packaged with no further setup necessary.
MySQL is usually put in /usr/local/mysql/bin/
You need to add this to your PATH, you can do this by adding the follwoing lines to your .bash_profile
PATH=$PATH:/usr/local/mysql/bin/
export PATH
The .bash_profile file is located in the root of your username directory.
Make sure you restart your Terminal for the setting to take affect.
And if you're not a command-line person, I highly recommend you also install the MySQL Preference Pane to start/stop the server and install Sequel Pro to create databases and run queries.
ftp://ftp.mysql.com/pub/mysql/download/gui-tools/MySQL.prefPane-leopardfix.zip
http://www.sequelpro.com/