![057ffca5a9309947627a98ec866cbcd6.png](https://i-blog.csdnimg.cn/blog_migrate/06ba3bcc536dfc8bb4eb59dd6f792001.jpeg)
1. Ubuntu中安装mysql
sudo apt-get install mysql-server安装,安装完成没有输入root提示密码,怎么登录??
2. 可以打开/etc/mysql/debian.cnf文件:
[client]
host = localhost
user = debian-sys-maint
password = eyPDN7kavhmjCZUn
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = eyPDN7kavhmjCZUn
socket = /var/run/mysqld/mysqld.sock
使用mysql -u debian-sys-maint -p ,即使用/etc/mysql/debian.cnf文件中的user和password可以登录
3. 登录成功后,可以修改root密码
MySQL5.7之后的版本MySQL5.7之后的版本
update mysql.user set authentication_string=password('newpassword') where user='root'
4. 修改完成后重启mysql 服务
sudo service mysql restart
5. mysql -u root -p 使用上面修改的root密码仍然不能登录,确定用户名和密码正确
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
6. 在使用/etc/mysql/debian.cnf文件中的用户名和密码登录
select user, plugin from mysql.user;
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| root | auth_socket |
| mysql.session | mysql_native_password |
| mysql.sys | mysql_native_password |
| debian-sys-maint | mysql_native_password |
+------------------+-----------------------+
4 rows in set (0.00 sec)
发现root 的plugin 是auth_socket 的,所有登录不
7. 修改root的plugin 为 mysql_native_password
mysql> update mysql.user set authentication_string=PASSWORD('newPwd'), plugin='mysql_native_password' where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
8. 重启服务后,root后正常登录