CentOS7安装和卸载MySQL
首先需要查看是否存在默认数据库MariaDB
# 查看
rpm -qa|grep mariadb
# 卸载
rpm -e mariadb-libs-5.5.65-1.el7.x86_64
error: Failed dependencies:
libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-9.el7.x86_64
libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-9.el7.x86_64
# 强制卸载(出现如上报错)
rpm -e --nodeps mariadb-libs-5.5.65-1.el7.x86_64
# 以下没有不执行
---输出---
mariadb-5.5.56-2.el7.x86_64
mariadb-libs-5.5.56-2.el7.x86_64
mariadb-server-5.5.56-2.el7.x86_64
---输出---
# 卸载
yum remove mariadb
# 清理残余
ls /etc/my.cnf
---输出---
/etc/my.cnf
---输出---
ll /var/lib/mysql/
---输出---
total 28700
-rw-rw---- 1 mysql mysql 16384 May 5 10:31 aria_log.00000001
-rw-rw---- 1 mysql mysql 52 May 5 10:31 aria_log_control
-rw-rw---- 1 mysql mysql 18874368 May 5 10:31 ibdata1
-rw-rw---- 1 mysql mysql 5242880 May 5 10:31 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 Oct 6 2017 ib_logfile1
drwx------ 2 mysql mysql 4096 Oct 6 2017 mysql
drwx------ 2 mysql mysql 4096 Oct 6 2017 performance_schema
---输出---
rm -rf /etc/my.cnf
rm -rf /var/lib/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;
quit
# CentOS系统安装好MySQL后,默认情况下不支持用户通过非本机连接上数据库服务器,下面是解决方法:
# 登录
mysql -uroot -p
# 选择数据库
use mysql;
# 开启远程连接(root 用户名、% 所有人都可以访问、password 密码)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
quit
# 重启
systemctl restart mysqld
# 如果还是不能访问大概率是因为防火墙没有放行,以下是关闭自带防火墙步骤:
# 查看是否开启
systemctl status firewalld.service
# 关闭
systemctl stop firewalld.service
# 再次查看
systemctl status firewalld.service
# 永久关闭
systemctl disable firewalld.service
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