Configuring a default root password for MySQL/MariaDB Use the following procedure to set a root password. To change the root password, type the following at the MySQL/MariaDB command prompt: ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyN3wP4ssw0rd'; flush privileges; exit; Store the new password in a secure location.
user SET Password=PASSWORD('new password') WHERE User='root'; FLUSH PRIVILEGES; mysqladmin -u root -p shutdown Note: Once you shutdown mysqladmin, you would be seeing the safe mode exits in Terminal 1. sudo service mysql start That's it and it works like a charm with the new password!
Try the command FLUSH PRIVILEGES
when you log into the MySQL terminal. If that doesn't work, try the following set of commands while in the MySQL terminal
$ mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET password=PASSWORD("NEWPASSWORD") WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
Change out NEWPASSWORD with whatever password you want. Should be all set!
Update: As of MySQL 5.7, the password
field has been renamed authentication_string
. When changing the password, use the following query to change the password. All other commands remain the same:
mysql> UPDATE user SET authentication_string=PASSWORD("NEWPASSWORD") WHERE User='root';
Update: On 8.0.15 (maybe already before that version) the PASSWORD() function does not work, as mentioned in the comments below. You have to use:
UPDATE mysql.user SET authentication_string='password' WHERE User='root';
If you don't remember the password you set for root and need to reset it, follow these steps:
sudo mysqld_safe --skip-grant-tables;
mysql -u root
For MySQL older than MySQL 5.7 use:
UPDATE mysql.user SET Password=PASSWORD('your-password') WHERE User='root';
For MySQL 5.7+ use:
USE mysql;
UPDATE mysql.user SET authentication_string=PASSWORD("your-password") WHERE User='root';
Refresh and quit:
FLUSH PRIVILEGES;
\q
Once you've installed MySQL, you'll need to establish the "root" password. If you don't establish a root password, then, well, there is no root password, and you don't need a password to log in.
So, that being said, you need to establish a root password.
Using terminal enter the following:
/usr/local/mysql/bin/mysqladmin -u root password NEW_PASSWORD_HERE
If you've made a mistake, or need to change the root password use the following:
cd /usr/local/mysql/bin/
./mysql -u root -p
> Enter password: [type old password invisibly]
use mysql;
update user set password=PASSWORD("NEW_PASSWORD_HERE") where User='root';
flush privileges;
quit
The instructions provided in the mysql website is so clear, than the above mentioned
$ sudo /usr/local/mysql/support-files/mysql.server stop
$ sudo /usr/local/mysql/support-files/mysql.server start --skip-grant-tables
/usr/local/mysql/bin/mysql
exit
or Ctrl + z $ sudo /usr/local/mysql/support-files/mysql.server stop
$ sudo /usr/local/mysql/support-files/mysql.server start
/usr/local/mysql/support-files/mysql -u root -p
Reference: http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
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
For the new Mysql 5.7, for some reason the bin commands of Mysql aren't attached to the shell, you have to do:
Restart the Mac after the installation.
Start Mysql:
System Preferences > Mysql > Start button
Go to Mysql install folder in the terminal:
$ cd /usr/local/mysql/bin/
Access to Mysql:
$ ./mysql -u root -p
and enter the initial password given to the installation.
In Mysql terminal change password:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassword';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With