Ubuntu 18.04 安装MySQL:ERROR 1698 (28000): Access denied for user 'root'@'localhost'

错误信息:

Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

导致原因
由于使用命令sudo apt-get install mysql安装时,并没有提示输入密码,则密码没有初始化

解决办法:

  • 思路:既然密码没有初始化,那么直接使用默认密码登录就可以了。
步骤:
1. 使用cat命令查看默认密码

sudo cat /etc/mysql/debian.cnf

显示的内容:

# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = 6b76NDnr65gNCcia
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = 6b76NDnr65gNCcia
socket   = /var/run/mysqld/mysqld.sock
2. 使用默认密码登录
# mysql -udebian-sys-maint -p
Enter password: 
...
mysql>
3. 修改密码
UPDATE mysql.user SET authentication_string=PASSWORD('root'), PLUGIN='mysql_native_password' WHERE USER='root';
4. 重启服务
/etc/init.d/mysql restart
5. 退出重新登录
mysql -u root -p root

即可登陆成功!!!

你可能感兴趣的:(Access,denied,for,user,'root'@'loca,mysql数据库)