一、查看centos版本
cat /etc/issue
安装mysql5.7
#下载rpm包
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19-1.el6.x86_64.rpm-bundle.tar
#创建mysql目录
mkdir /home/mysql
#解压
tar -xvf mysql-5.7.19-1.el6.x86_64.rpm-bundle.tar -C /home/mysql
#安装numactl和mysql
yum install -y numactl
cd /home/mysql
按以下顺序安装相关rpm:
安装cdh时需要
[root@arno-cents mysql]# rpm -ivh mysql-community-common-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-common-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-common ########################################### [100%]
[root@arno-cents mysql]# rpm -ivh mysql-community-libs-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-libs-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-libs ########################################### [100%]
[root@arno-cents mysql]# rpm -ivh mysql-community-libs-compat-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-libs-compat-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-libs-co########################################### [100%]
[root@arno-cents mysql]# rpm -ivh mysql-community-client-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-client-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-client ########################################### [100%]
[root@arno-cents mysql]# rpm -ivh mysql-community-server-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-server-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-server ########################################### [100%]
#启动mysql
service mysqld start
#查看默认生成的密码
sudo grep 'temporary password' /var/log/mysqld.log
#登陆mysql
mysql -uroot -p
#第一次重设密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
#修改host值
mysql>use mysql;
mysql> update user set host = '%' where user ='root';
mysql>flush privileges;
mysql> select host,user from user where user='root';
#修改为简单密码
#只验证密码长度
set global validate_password_policy=0;
mysql>flush privileges;
#查看密码长度
select @@validate_password_length;
修改默认密码的长度(这里修改为6)
set global validate_password_length=6;
mysql>flush privileges;
#重设密码为passwd
ALTER USER 'root'@'%' IDENTIFIED BY 'passwd';
mysql>flush privileges;
exit;
#设置开机自启动
chkconfig mysqld on
#重新用新密码登陆
mysql -uroot -ppasswd
mysql> Grant all privileges on *.* to 'root'@'%' identified by 'passwd' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
不按指定顺序安装mysql相关包会报如下类错误:
error: Failed dependencies:
mysql-community-libs(x86-64) >= 5.7.9 is needed by mysql-community-client-5.7.13-1.el7.x86_64
mariadb is obsoleted by mysql-community-client-5.7.13-1.el7.x86_64
yum -y remove mysql-libs-*
使用Yum安装东西时,如果有强制退出过yum或yum异常结束,再下次使用yum命令时会提示:There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them。
可以通过以下方法处理:
yum -y install yum-utils
yum clean all
yum-complete-transaction --cleanup-only
一 、yum方式安装的mysql
yum remove mysql mysql-server mysql-libs compat-mysql51
rm -rf /var/lib/mysql
rm /etc/my.cnf
查看是否还有mysql软件:
rpm -qa|grep mysql
如果存在的话,继续删除即可。
二、rpm方式安装的mysql
a)查看系统中是否以rpm包安装的mysql:
[root@arno-cents mysql]# rpm -qa | grep -i mysql
mysql-community-libs-5.7.19-1.el6.x86_64
mysql-community-client-5.7.19-1.el6.x86_64
mysql-community-server-5.7.19-1.el6.x86_64
mysql-community-common-5.7.19-1.el6.x86_64
b)依次卸载mysql
[root@arno-cents mysql]#rpm -e mysql-community-libs-5.7.19-1.el6.x86_64
[root@arno-cents mysql]# rpm -e ...
d)删除分散mysql文件夹
[root@arno-cents mysql]# whereis mysql
mysql: /usr/lib/mysql /usr/share/mysql
清空相关mysql的所有目录以及文件
rm -rf /usr/lib/mysql
rm -rf /usr/share/mysql
[root@arno-cents mysql]#find / -name mysql
rm -rf ...