MySQL的卸载与安装
环境:Ubuntu20.04
MySQL版本: 5.7
注:Ubuntu 20.04 版本系统自带的 MySQL 版本是 8.0,本文给出 5.7 版本的安装教程。
MySQL的彻底卸载
1、删除mysql的数据文件
sudo rm /var/lib/mysql/ -R
2、删除mysql的配置文件
sudo rm /etc/mysql/ -R
3、删除依赖项,清除残留数据
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
4、查看依赖项,看是否删除干净 (如果执行下条命令无任何输出咋删除干净了)
dpkg --list|grep mysql
未卸载干净的情况只需根据依赖名手动卸载即可,如下图:
ubuntu20.04 安装 MySQL5.7
1、添加MySQL源
sudo vim /etc/apt/sources.list.d/mysql.list
添加以下内容:
deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-apt-config
deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-5.7
deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-tools
deb-src http://repo.mysql.com/apt/ubuntu/ bionic mysql-5.7
2、更新
sudo apt update
更新过程中如果出现如下错误,
W: GPG error: http://repo.mysql.com/apt/ubuntu bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 467B942D3A79BD29
E: The repository 'http://repo.mysql.com/apt/ubuntu bionic InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
则执行以下命令后,再更新。
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
3、查看版本信息 (确认之前步骤成功)
此时通过 sudo apt-cache policy mysql-server
查看版本,就能显示 5.7.40-1ubuntu18.04
4、安装MySQL
sudo apt install mysql-client=5.7.40-1ubuntu18.04
sudo apt install mysql-server=5.7.40-1ubuntu18.04
5、验证
安装成功…
初始环境配置
1、进入数据库设置 root
账户的密码和权限 (shell)
sudo mysql
2、切换 mysql
数据库 (mysql)
use mysql;
3、修改root用户密码 (mysql)
-- 这句话原封不动地执行
update user set plugin='mysql_native_password' where user='root';
- 这里'密码'的位置设置为你自己的密码
-- root是用户名不要改
update user set authentication_string=PASSWORD('密码') where user='root';
4、设置远程登录 (mysql)
设置root账号允许远程登录,默认只允许本地登录
-- 这里的'密码'要跟上面的密码保持一致
-- root是用户名,不要改
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
5、刷新权限 (mysql)
FLUSH PRIVILEGES;
6、退出数据库 (mysql)
exit;
7、修改配置文件,注释掉绑定地址 (shell)
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
8、重启数据库 (shell)
sudo service mysql restart
9、正常登录 (shell)
mysql -uroot -p
输入密码即可
Original: https://blog.csdn.net/qq_40342400/article/details/127813107
Author: Lu Zelin
Title: MySQL的卸载与安装
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/653958/
转载文章受原作者版权保护。转载请注明原作者出处!