I just installed MySQL on Mac OS X. The next step was setting the root user password, so I did this next:
- Launch the terminal app to access the Unix command line.
Under the Unix prompt I executed these commands:
$ cd /usr/local/mysql/bin $ ./mysqladmin -u root password 'password'
But, when I execute the command
$ ./mysql -u root
, this is the answer:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 224
Server version: 5.5.13 MySQL Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
I can get into the mysql
command line without any password!
Why is this?
Stop the mysqld server.
System Preferences
>MySQL
>Stop MySQL Server
sudo systemctl stop mysqld.service
Start the server in safe mode with privilege bypass
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
In a new terminal window:
sudo /usr/local/mysql/bin/mysql -u root
This will open the mysql command line. From here enter:
UPDATE mysql.user SET authentication_string=PASSWORD('NewPassword') WHERE User='root';
FLUSH PRIVILEGES;
quit
Stop the mysqld server again and restart it in normal mode.
sudo /usr/local/mysql/support-files/mysql.server restart
sudo systemctl restart mysqld
The methods mentioned in existing answers don't work for mysql 5.7.6 or later. According mysql documentation this is the recommended way.
B.5.3.2.3 Resetting the Root Password: Generic Instructions
MySQL 5.7.6 and later:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Reference: https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
If you can't remember your password, @radtek's answer worked for me except in my case I had set up MySQL using brew which meant that steps 1 and 2 of his answer had to be changed to:
/usr/local/bin/mysql.server stop
/usr/local/bin/mysqld_safe --skip-grant-tables
Note: the lack of
sudo
.Stopping MySQL Server
sudo /usr/local/mysql/support-files/mysql.server stop
Starting MySQL in safe mode
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables &
Changing the root password
/usr/local/mysql/bin/mysql -u root
Testing
Run
/usr/local/mysql/bin/mysql -u root
Now enter the new password to start using MySQL.