I've decided to try MAMP on new Mac OS X 10.5. Mostly because PHP bundled with Leopard doesn't have GD library (otherwise it has quite cool set of modules). The other reason that is better Marc Liyanage's PHP installer is not yet ready for Leopard.
But after backing up all my MySQL databases (around 200Mb dump) it turned out that you can't acces MAMP's mysql via terminal to restore it (or I was something terribly missing from FAQs).
Here is a hint. You have to create symlink from local mysql.sock to MAMP:
sudo mkdir /var/mysql
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock
sudo chown _mysql /var/mysql/mysql.sock
sudo chmod 777 /var/mysql/mysql.sock
Hope it'll save somebody's few minutes.
UPD #1: Just in sake of more comfort you can add MAMP's mysql to bash profile (don't forget to reopen terminal window to let it work):echo 'export PATH=/Applications/MAMP/Library/bin:$PATH' >> ~/.bash_profile
UPD #2: This hint works on Snow Leopard (10.6) just fine.
Thank you so much for posting this solution. You saved me more than a few minutes.
This not only saved me a few minutes but a huge headache as well. This was the big show stopper when it came to creating a local development environment.
Thanks for taking the time to post this, it really helped me out.
Hey Andrey,
I did what you wrote in your post but still can't get mysql to work. After completing the described commands, where do I need to navigate to and by which command can I execute mysql?
Thanks a lot by a total Mac-Newbie :)
Regards
Frederik
After applying this little hint you can use terminal to access the MySQL under MAMP. Searching say for "mysql commands" in google will give you more info on how to use MySQL from command line interface (read terminal).
A quick tip:
mysql -u yourusername -p Databasename < DatabasenameBackupFile.sql
This will import single database backup back to MySQL (the empty database should already exist on the your MAMP)
mysql -u yourusername -p < AllDatabaseBackupFile.sql
This will import all databases backup back to MySQL and create all the db. It will help only if you saved complete sql dump from all your databases.
And of course you still can use phpMyAdmin supplied with MAMP.
You'll also probably need to change directories to where the mysql binary file is located,
cd /Applications/MAMP/Library/bin/
And by default the "mysql" file won't be set to execute as a command and so you'll probably see this error:
-bash: mysql: command not found
So just add a "./" in front of it, and try this:
./mysql -u yourusername -p yourpassword < AllDatabaseBackupFile.sql
This should also work:
./mysql --user=yourusername --password=yourpassword < AllDatabaseBackupFile.sql
You'll of course need to probably point to where ever you're download file is located. Perhaps something like: /Users/kent/Sites/AllDatabaseBackupFile.sql;
If you run more than one version of MySQL on your machine, a solution to this problem is to add the "--socket=" directive to your mysql command like so:
mysql --socket=/Applications/MAMP/tmp/mysql/mysql.sock -u username -p
This will make sure the right version of the sock is used and you won't need to overwrite any other versions of MySQL you already have installed.
thanks for the tips, i'll try.
Are you running with some other instance of mysql installed?
You can specify the socket on the command line like:
/Applications/MAMP/Library/bin/mysql -uroot -proot --socket=/Applications/MAMP/tmp/mysql/mysql.sock
I actually switched back to Mark's PHP for 10.5 distro as soon as it was available. It's still in beta but I didn't have any troubles with it yet.
thanks a lot!
but before running you tutorial, you have to mention that MAMP is running, so we can get an active mysql.sock
thanks again :)
Tested it just now & it works great.
Do you have any idea how do this?
Not really unfortunately. As I mentioned earlier I'm back to Entropy PHP distribution for a while. In this case svn works just fine.
Don't forget to check Versions application by the way. It is amazing.
Hi, I think this solution is the one that I'm looking for.
Though, I can't get it to work. I'm a newb in Unix scripting i Terminal, and when i type "sudo ... " it asks for my password, of course. Nothing wrong with that, but say if you don't have any password on your Mac? I just hit 'Enter' and nothing seem to happen. No sign at all.
This is the first time I try MySQL-development on a Mac; I'm used to the Windows way. In WAMP, all I have to do is to click on the small icon, and choose 'MySQL Command Line' or something like that. I've found NONE documentation of this in MAMP. On top of that, I want to be able to access a MySQL command line in Coda too ..
Thanks in ahead.
I had the same problem (it may not a prob) but I just try one of above line. (even easier - pwolanin | Mon, 2008-06-09 21:09 command line
/Applications/MAMP/Library/bin/mysql -uroot -proot --socket=/Applications/MAMP/tmp/mysql/mysql.sock
It works!
##### CREATE NEW EMPTY DATABASE VIA MAMP PHPMYADMIN #####
##### COPY SQL DUMP TO: #####
/Applications/MAMP/Library/bin/
##### CREATE A SOCKET TO MAMP MYSQL IN TERMINAL ######
/Applications/MAMP/Library/bin/mysql -uroot -proot --socket=/Applications/MAMP/tmp/mysql/mysql.sock
##### AT MYSQL PROMPT SET MYSQL TO 'USE' NEW DB ######
\u yourNewDatabase
##### AT MYSQL PROMPT RESTORE SQL DUMP ######
\. yourMysqlFile.sql
I agree, I don't want to disturb the mysql that comes with Leopard ... I just want to ignore it. MAMP is the only mysql that I really *use*.
So, this works for me.
I delete the link to the built-in mysql and then create a new symbolic link in /usr/local/bin for the mysql that comes with MAMP. That way I can execute mysql from any path and don't have to type a long path. Ofcourse, this only works when MAMP is running.
1) cd /usr/local/bin/
2) sudo rm mysql
3) sudo ln -s /Applications/MAMP/Library/bin/mysql mysql
Oh, that password you have to enter ... that's the root or default users password. The same one you enter to install software.
You saved me a lot of time. THANKS, THANKS, THANKS... :)
Hello, I'm getting closer but could use a tip. No problem connecting to mysql following the above instructions using Terminal. However, following "so the full process then for me is:" from Kayless, I enter "u yourNewDatabase" (using the proper name), mysql responds "database changed", then I enter "\. mydatabase.sql" (which is a .sql file in MAMP/Library/bin. Now I get the error "Failed to open file 'foilive.sql', error: 2".
Thanks for any advice.
BTW, the reason I'd like to be able to import into MAMP from the command line is I'm always getting "max_packet_errors" when using php my admin. The file is usually around 10mb but sometimes there are cache tables of around 1000kb; if I empty them I can import through phpmy admin.
Thanks again.
Did you ever resolve this error?
Thanks for this, i was struggling to connect mysql administrator gui to mamp's mysql db, but of course you just paste the socket into the option (click advanced options)
/Applications/MAMP/tmp/mysql/mysql.sock
easy peasy!
I <3 you
This is perfect! Thank you ever so much for saving me a whole lot of headaches.
If you're like me and make silly mistakes, I implemented your ln fix before launching MAMP. Reversing my steps, I see it was not necessary at all (10.6, running MAMP).
For me, the message was:
$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2)
hth
I´m sorry, I´m not an experimented developer, after reading your post what I understood is that I open terminal and type :
sudo mkdir /var/mysql
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock
sudo chown _mysql /var/mysql/mysql.sock
sudo chmod 777 /var/mysql/mysql.sock
but just after I type the first line:
udo mkdir /var/mysql
I´m prompted to write my password, after I write my password, I placed the next 3 lines:
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock
sudo chown _mysql /var/mysql/mysql.sock
sudo chmod 777 /var/mysql/mysql.sock
and I don´t receive any answer from the terminal...
close terminal and paste the final update:
echo 'export PATH=/Applications/MAMP/Library/bin:$PATH' >> ~/.bash_profile
and still can´t start any mysql server, I´m running 10.6.2... am I doing it all wrong?
Hope you can help me.
Thanks in advanced!
You only need to run those commands once. Make sure your MAMP is running before you try this in terminal.
Open up a new Terminal and enter the following:
(Anytime you see a dollar sign before a command, it means do it in terminal w/o the dollar sign)
$mysql -u username -p
This should prompt you for your mysql password
After you type in your MYSQL password, the command line will change to
mysql >
You can use the command "show databases;" minus the quotes to see all your databases in the terminal window.
Example, your terminal window should look like this
mysql > show databases;
You can also enter Queries via the mysql > prompt
Example
Make sure you've selected what database to use, with the USE command first "USE exampledatabase" or you'll get an error.
mysql > USE exampledatabase;
..
To do a simple select it is like so:
mysql > SELECT * FROM exampletable;
Worked perfectly.
Thank you, thank you :)
Still great after all this years!
Worked really well. :) Nice to see a Drupal-powered site too!
Thanks a lot for posting the solution! Do you know if the hint works on Lion?
Yup, it should work on Lion just fine.
Thank you for the tip! Have a nice day!
Thanks, this works great on lion! Just had to sudo rm -rf /var/mysql first to get it to work
when I run
/var/mysql/mysql.sock
I got
-bash: /var/mysql/mysql.sock: Permission denied
For anyone problems with this method, here's a link to another solution that uses .bash_profile.
http://thewebfactory.wordpress.com/2011/10/26/symfony-2-pdoexception-cou...
Thanks!
I was able to get this to work on Mac Lion OS too. For MAMP and the MySQL installer package.
You absolute legend!
Saved me a lot of hassle.
Ryan
Muchas gracias!!! Funciona de maravilla