环境信息
1 2 3 4 5 6
| ubuntu@VM-0-7-ubuntu:~/blog$ lsb_release -a No LSB modules are available. Description: Ubuntu 18.04.4 LTS
ubuntu@VM-0-7-ubuntu:~/blog$ mysql mysql Ver 14.14 Distrib 5.7.38, for Linux (x86_64) using EditLine wrapper
|
修改配置文件
在[mysqld]块内加上skip-grant-tables
,然后保存退出,sudo service mysql restart
重启mysql
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking skip-grant-tables
|
重设密码
终端输入mysql -u root
直接进入mysql,执行如下语句
1 2 3
| use mysql; update user set authentication_string=password("新密码") where user="root"; flush privileges;
|
然后quit
退出mysql
还原配置文件
重新回到刚才的配置文件,将加进去的skip-grant-tables
注释掉即可。