mysql -- reset password

http://blog.51cto.com/legehappy/1979492

To solve Mysql forgot password:

1. First stop the running MySQL process:
[root@cml5 ~]# systemctl stop mysqld

2. Start MySQL in safe mode:

[root@cml5 ~]# /usr/local/mysql/bin/mysqld_safe--skip-grant-tables &
##Or add it under my.cnf file, delete
skip-grant-tables after execution

[root@cml5 ~]# cat /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/mydata
socket=/usr/local/mysql/mysql.sock
log_bin=/usr/local/mysql/mydata/mysql-bin
server-id=1
skip-grant-tables


Then restart mysql
to enter mysql (password-free)
and change the password;
3. After completion, you can enter MySQL without password, and then change the password:

(3) Run /usr/local/mysql/bin/mysql -u root -p and press Enter key to enter
[root@cml5 ~]#  /usr/local/mysql/bin/mysql -u root -p

mysql> use mysql;
mysql> update user set password=password('123') where user='root' and host='localhost';
##If it is after mysql5.7, the password field is changed to authentication_string:
mysql> update user set authentication_string=password('redhat') where user='root'and host='localhost';
mysql> flush privileges;
mysql> ALTER user 'root'@'localhost' identified by 'redhat';
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326081543&siteId=291194637