Skip to main content

MySQL reset root user password

MySQL reset root user password:

Check MySQL status:
strace -e stat64 mysqld --print-defaults > /dev/null

When you don't know mysql user password and would like to reset password:

https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

# service mysql stop
# mysqld_safe --skip-grant-tables &
# mysql -u root
mysql> show databases;
mysql> use mysql
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('mysql'), password_expired = 'N' WHERE User = 'root' AND Host = 'localhost';
mysql> flush privileges;
mysql> quit
# service mysql stop
# service mysql start

Get temporary password for mysql user root, after installation:

# grep 'temporary password' /var/log/mysqld.log
[Server] A temporary password is generated for root@localhost: #=lkkq7kpuFj

$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.11

Copyright (c) 2000, 2018, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newcode';
Query OK, 0 rows affected (0.03 sec)





Comments