CentOS7安装和卸载MySQL
2020-07-15 本文已影响0人
骆昊宇
CentOS7安装和卸载MySQL
壹、安装
1.1 找到安装的源
wget http://repo.mysql.com/mysql57-community-release-el7-9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
1.2 更新yum和系统
yum check-update
yum update
1.3 安装MySQL
yum install mysql mysql-server
# 如果中断或者关机就执行卸载的步骤再重新操作
1.4 跳过密码验证及修改密码
vim /etc/my.cnf
# 添加一行,修改完后切记注释掉
skip-grant-tables
# 重启
systemctl restart mysqld
#直接输入mysql即可无密码登录
update mysql.user set authentication_string=password('***') where user='root' and Host ='localhost';
flush privileges;
quit
# 修改跳过密码
# 重启
# 登录
mysql -u root -p
# 重新修改密码
set global validate_password_policy=0;
ALTER USER 'root'@'localhost' IDENTIFIED BY '***' PASSWORD EXPIRE NEVER;
flush privileges;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '***' WITH GRANT OPTION;
flush privileges;
quit
1.5 修改字符编码为utf-8
show variables like 'char%';
修改my.conf
vim /etc/my.cnf
# 增加以下内容
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
# 登录mysql查看
show variables like 'char%';
贰、卸载
2.1 查看yum是否安装过mysql
yum list installed mysql*
2.2 yum卸载,根据列表上的名字
yum remove mysql-community-client mysql-community-common mysql-community-libs mysql-community-libs-compat mysql-community-server mysql57-community-release
rm -rf /var/lib/mysql
rm /etc/my.cnf
2.3 rpm查看安装
rpm -qa | grep -i mysql
2.4 rpm卸载
rpm -e mysql57-community-release-el7-9.noarch
rpm -e mysql-community-server-5.7.17-1.el7.x86_64
rpm -e mysql-community-libs-5.7.17-1.el7.x86_64
rpm -e mysql-community-libs-compat-5.7.17-1.el7.x86_64
rpm -e mysql-community-common-5.7.17-1.el7.x86_64
rpm -e mysql-community-client-5.7.17-1.el7.x86_64
cd /var/lib/
rm -rf mysql/
2.5 清除余项
whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/local/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
#删除上面的文件夹
rm -rf /usr/bin/mysql
2.6 删除配置
rm –rf /usr/my.cnf
rm -rf /root/.mysql_sercret
2.7 剩余配置检查
chkconfig --list | grep -i mysql
chkconfig --del mysqld
# 根据上面的列表,删除,如:mysqld