Friday, August 28, 2009

Using MySQL command line with MAMP

To use the MySQL command line with MAMP or MAMP PRO, perform the following steps:
  1. Start MAMP or MAMP PRO
  2. Start the server
  3. Open Terminal (Applications -> Utilities)
    Type in: (one line)
    /Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot
Now you can use the MySQL command line. For exmaple to show all your databases with show databases;.

Share/Save/Bookmark

8 Kommentare:

  1. Do you have to do this all the time? As in each terminal session you have to type in that line to use mysql in command line? What is the stuff I need to add to my .profile to access mysql directly without having to put that pathname in all the time?

    ReplyDelete
  2. I created symbolic links like so. Now all I have to do is type mysql to connect to the server.

    sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/local/bin/mysql

    You can also set this up for mysqldump etc..

    ReplyDelete
  3. Another easy way to do it is add the following lines to your .profile file in your home directory:

    export PATH=$PATH:/Applications/MAMP/Library/bin

    then type ". .profile" (without the quotes) to reload your profile

    Then type: echo $PATH
    and make sure that line is in there. Then you have access to everything in the bin directory so you can use the mysqladmin tool if you need to.

    ReplyDelete
  4. Thank for MySQL command tutorial. I will use it.

    ReplyDelete
  5. Thank you as an old user of Linux to a new user of mac this was a nice nudge in the right direction.

    ReplyDelete
  6. I get this error:
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2)

    Even this didn't help:
    sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

    ReplyDelete
    Replies
    1. It worked thanks!

      I just had to restart the MySQL server.

      Thanks

      Delete