解决Mysql忘记密码:
1、首先停止正在运行的MySQL进程:[root@cml5 ~]# systemctl stop mysqld
2、以安全模式启动MySQL:[root@cml5 ~]# /usr/local/mysql/bin/mysqld_safe--skip-grant-tables &
##或者在my.cnf文件下添加,执行完后就删除掉
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(免密码)
然后修改密码;
3、完成以后就可以免密进入MySQL了,然后修改密码:
(3)运行 /usr/local/mysql/bin/mysql -u root -p 按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';
##假如是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)