解決Mysql忘記密碼:mysql
[root@cml5 ~]# systemctl stop mysqld
[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
(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)