mysql8 ubuntu第一次登陆修改root密码

  1. 查看初始登录密码
sudo cat -n /etc/mysql/debian.cnf
1    # Automatically generated for Debian scripts. DO NOT TOUCH!
2    [client]
3    host     = localhost
4    user     = debian-sys-maint
5    password = p6OUNvUoUrxSvkh8
6    socket   = /var/run/mysqld/mysqld.sock
7    [mysql_upgrade]
8    host     = localhost
9    user     = debian-sys-maint
10    password = p6OUNvUoUrxSvkh8
11    socket   = /var/run/mysqld/mysqld.sock

  1. 使用用户debian-sys-maint登陆
sudo mysql -u debian-sys-maint -p
  1. 修改mysql.user
# 修改
update mysql.user set plugin='mysql_native_password' where user='root';
flush privileges;
# 查看结果
select host, user, authentication_string, plugin from mysql.user;
# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'helloworld123';
flush privileges;
# 查看结果
select host, user, authentication_string, plugin from mysql.user;
  1. 修改结果
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host      | user             | authentication_string                                                  | plugin                |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| localhost | root             | *1219A58DFAAB1F15569A4FE8C43B60C5ECF55D3A                              | mysql_native_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
  1. 退出mysql,重启mysql服务
sudo service mysql restart
  1. 登陆,使用新的密码,且可以不再使用sudo
mysql -u root -p

你可能感兴趣的:(ubuntu,debian,linux)