Ubuntu20.04彻底卸载并重装MySQL 8.0数据库

Rain2021-02-10 14:20technologyLinuxMySQL

卸载

# 运行卸载
sudo apt-get remove mysql-common mysql-server-8.0

# 在终端中查看MySQL的依赖项
dpkg --list|grep mysql

# 卸载相关依赖项
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

重新安装并修改默认密码

# 更新源并安装mysql8.0
sudo apt update
sudo apt install mysql-server

#安装成功后停止服务
sudo service mysql stop

# 启动服务
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

# 使用root登录
mysql -u root mysql

# 为了解决 The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement 这个错误 先刷新一下权限表
flush privileges;

# 修改root用户密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

# 修改绑定IP,方便Navicat连接
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
修改 bind-address = 0.0.0.0

Last Updated 4/4/2022, 11:33:25 AM