Mysql – How to set the MySQL password on Mac OS X

installationMySQLmysqladmin

I've downloaded mysql 5.25 on mac os x Lion (10.7.4). I just tried setting my password in the usual way, however I'm getting an access denied error which is odd:

[user@Macintosh:~] #mysqladmin -uroot password 'secret'

mysqladmin: connect to server at 'localhost' failed

Is there something I'm missing about setting the root password for this version of mysql on this version of the mac? The database is definitely running according to what I see in the control panel / ps -ef.

Best Answer

Are you getting an access denied error or something else? mysqladmin should be printing a second line with more details, too. Have you looked over the installation notes for 5.5.25 (the current GA) at http://dev.mysql.com/doc/refman/5.5/en/osx-installation-notes.html ?

Sometimes the client don't look for the mysql socket file in the same place as it was written, or something deletes it if it's written in /tmp or another similar location. If so then connecting over TCP might work (add -h 127.1 to the command line options).

If you need to reset the password, you can stop mysql and start it (temporarily) with an option to just allow any access without authentication. I find the easiest way to get the current options it's running with is ps axwwwwwww | grep mysql.