Configuring terminal to work with MAMP mysql on Leopard
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.
- Add new comment
- 2046 reads
Comments:
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 yourpassword 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 yourpassword < 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.
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.sockI 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 :)

Configuring terminal to work with MAMP mysql on Leopard
Thank you so much for posting this solution. You saved me more than a few minutes.