MySQL安装报错部分解决方案
1.ERROR 1698 (28000): Access denied for user 'root'@'localhost'
一般出现这种情况多数是安装新版本mysql,root密码是随机的,也不是空密码,所以要通过查看随机密码进入,再进行修改原来的密码。
解决方案
1.查看内置用户的随机密码
下载安装MySQL的过程中,系统会自动给我们创建一个用户,我们借助如下指令便可以查看该用户信息:
sudo cat /etc/mysql/debian.cnf
返回:
❯ sudo cat /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = R4ZiuvNnNykAuP9N
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = R4ZiuvNnNykAuP9N
socket = /var/run/mysqld/mysqld.sock
2.进入MySQL
然后使用debian-sys-maint
和R4ZiuvNnNykAuP9N
(看password
那一行,这个是随机生成的,我的和你的不一样)进入MySQL:
mysql -u debian-sys-maint -p
在显示Enter password:
之后输入password
那一行后面的密码,此时密码不会显示(copy下来就对了
3.修改root账户密码
先查看一下原来的用户表:
use mysql;
select user,plugin from user;
输出:
mysql> use mysql;
t user,plugin from user;Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select user,plugin from user;
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| lkhsss | caching_sha2_password |
| debian-sys-maint | caching_sha2_password |
| mysql.infoschema | caching_sha2_password |
| mysql.session | caching_sha2_password |
| mysql.sys | caching_sha2_password |
| root | auth_socket |
+------------------+-----------------------+
6 rows in set (0.00 sec)
可以看到root账户的密码格式为auth_socket
。
现在来修改一下root账户的密码格式:
update user set plugin='mysql_native_password' where user='root'; # 修改其密码格式
select user,plugin from user; # 查询其用户
输出:
mysql> update user set plugin='mysql_native_password' where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> select user,plugin from user;
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| lkhsss | caching_sha2_password |
| debian-sys-maint | caching_sha2_password |
| mysql.infoschema | caching_sha2_password |
| mysql.session | caching_sha2_password |
| mysql.sys | caching_sha2_password |
| root | mysql_native_password |
+------------------+-----------------------+
6 rows in set (0.00 sec)
修改好后要刷新权限
flush privileges;
然后新增密码:
alter user 'root'@'localhost' identified by '密码';
再刷新一次
flush privileges;
退出
exit
4.重启服务
service mysql restart
现在即可用mysql -u root -p
,然后使用刚刚设置的密码登陆了
MySQL安装报错部分解决方案
https://lkhsss.github.io/数据库/MySQL/mysql安装报错部分解决方案/