528 字
3 分钟
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 = localhostuser = debian-sys-maintpassword = R4ZiuvNnNykAuP9Nsocket = /var/run/mysqld/mysqld.sock[mysql_upgrade]host = localhostuser = debian-sys-maintpassword = R4ZiuvNnNykAuP9Nsocket = /var/run/mysqld/mysqld.sock2.进入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 namesYou can turn off this feature to get a quicker startup with -A
Database changedmysql> 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;退出
exit4.重启服务
service mysql restart现在即可用mysql -u root -p,然后使用刚刚设置的密码登陆了
MySQL安装及部分报错解决方案
https://www.lkhssssss.cn/posts/mysql-install-solution/分享文章
生成精美分享图或复制链接,与更多人分享本文。
继续阅读
换条路线
从其他文章中稳定抽取
最后更新于 ,距今已过 1302 天
部分内容可能已过时