Mysql default root password on Centos7

After you install Mysql community server on “Centos7” machine using yum, you might get the “access denied” error if you try to login to mysql with empty root password. 

See below

1 2 # mysql ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)

Unlike earlier versions, here mysql set a default password while starting it for first time.The new password will be printed in the logs also. Let us see how to recover mysql default root password  .

To recover the mysql root password, check the mysql logs. On a Centos machine you can find it at “/var/log/mysqld.log” by default. You will find a line similar to this, in the logs

1 2 3 4 5 6   20170811T10:10:29.716964Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened. 20170811T10:10:29.717468Z 1 [Note] A temporary password is generated for root@localhost: cUgI:,Ve;6qd 20170811T10:10:32.378279Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use explicit_defaults_for_timestamp server option (see documentation for more details). 20170811T10:10:32.379514Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.19) starting as process 5707 ...  

As you can see in the logs, it set a temporary password which is “cUgI:,Ve;6qd”

Now we can login to mysql with mysql default root password  password

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19   # mysql -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.19   Copyright (c) 2000, 2017, 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> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql>  

 

But mysql wont allow you to run any commands without reseting the temporary password. Now we have to reset the temporary password.

1 2 3 4 5   mysql> SET PASSWORD = PASSWORD([email protected]); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql>  

Now we reset the password for mysql root user. You can exit from the console and login again with new password.

As always, feel free to drop us a note if you have any queries or feedbacks using our comment form below. Always happy to help you ????

Author: , 0000-00-00