mysql--重置密码

解决Mysql忘记密码:mysql

 

一、首先中止正在运行的MySQL进程:

[root@cml5 ~]# systemctl stop mysqld


二、以安全模式启动MySQL:

[root@cml5 ~]# /usr/local/mysql/bin/mysqld_safe--skip-grant-tables &

##或者在my.cnf文件下添加,执行完后就删除掉sql

 skip-grant-tables

安全

[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


而后重启mysql
进入mysql(免密码)
而后修改密码;
bash

三、完成之后就能够免密进入MySQL了,而后修改密码:

(3)运行 /usr/local/mysql/bin/mysql -u root -p 按Enter键进入socket

[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'; 
##假如是mysql5.7以后的就password字段改为了authentication_string:
mysql> update user set authentication_string=password('redhat') where user='root'and host='localhost';
mysql5.7以上版本-->    UPDATE user SET authentication_string=PASSWORD("root") WHERE User="root";
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)

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
今天在MySql5.6操做时报错:You must SET PASSWORD before executing this statement解决方法,须要的朋友能够参考下
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement 
mysql> create database yan1; 
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement 
mysql> SET PASSWORD = PASSWORD('123456'); 
Query OK, 0 rows affected (0.03 sec)
相关文章
相关标签/搜索