首次登录mysql(5.7)或忘记密码解决方法【ubuntu】

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bondsui/article/details/83116268

使用debian-sys-maint登录系统,修改密码

查看debian-sys密码

sui@sui-VirtualBox:/etc/mysql$ sudo cat /etc/mysql/debian.cnf 
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = uLz3xiuwdnpAmWt4
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = uLz3xiuwdnpAmWt4
socket   = /var/run/mysqld/mysqld.sock

记住上面user和password

使用debian-sys-maint登录并修改密码

sui@sui-VirtualBox:/etc/mysql$ mysql -u debian-sys-maint -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.23-0ubuntu0.18.04.1 (Ubuntu)

成功登陆mysql

mysql> update mysql.user set authentication_string=password('root') where user='root' and Host ='localhost';
mysql> update user set plugin="mysql_native_password"; 
mysql> flush privileges;

刷新权限后,quit退出会话。

使用新设置的root密码登录root

sui@sui-VirtualBox:/etc/mysql$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.23-0ubuntu0.18.04.1 (Ubuntu)

成功修改root密码并登录

猜你喜欢

转载自blog.csdn.net/bondsui/article/details/83116268