Ubuntu20.04 安装、卸载MySQL8和操作系统非root用户登录报错:ERROR 1698 (28000): Access denied for user ‘root‘@‘localhost

安装MySQL8

安装mysql-server sudo apt install mysql-server

初始化配置信息 sudo mysql_secure_installation

VALIDATE PASSWORD COMPONENT…(使用密码强度校验组件) 输入: n
New Password:(设置新密码,并重复一遍)
Remove anonymous users (删除匿名用户) n
Disallow root login remotely(拒绝远程root账号登录) n
Remove test database and access to it(移除test数据库) n
Reload privilege tables now (现在就重新载入权限表) y

解决 操作系统非root用户登录报错:ERROR 1698 (28000): Access denied for user ‘root’@‘localhost’

sudo mysql -uroot -p
配置root用户外网也可以连接并登录
use mysql
select host,user,plugin from user;

+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | auth_socket           |
| localhost | debian-sys-maint | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
+-----------+------------------+-----------------------+

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '$pass';
FLUSH PRIVILEGES;# 刷新权限
select host,user,plugin from user;

+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | mysql_native_password |
| localhost | debian-sys-maint | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
+-----------+------------------+-----------------------+

再次登录:

mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 8.0.26-0ubuntu0.20.04.2 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> 

MySQL8 卸载

查看MySQL依赖 : dpkg --list|grep mysql

卸载: sudo apt-get remove mysql-common

卸载: sudo apt-get autoremove --purge mysql-server-8.0(这里版本对应即可)

清除残留数据: dpkg -l|grep ^rc|awk '{print$2}'|sudo xargs dpkg -P

再次查看MySQL的剩余依赖项: dpkg --list|grep mysql(这里一般就没有输出了,如果有执行下一步)

继续删除剩余依赖项,如:sudo apt-get autoremove --purge mysql-apt-config

在执行过程中有的需要sudo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值