mysql官网下载地址:https://dev.mysql.com/downloads/mysql/
本次操作系统是 阿里云服务器 CentOS 6.9 64位
下载得到tar 包: mysql-5.7.21-1.el6.x86_64.rpm-bundle.tar
该连接是我安装mysql时的参照文章:::
安装前检查服务器是否已安装MySQL,如已安装则将其卸载:
rpm -qa|grep mysql
mysql-libs-5.1.71-1.el6.x86_64
rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64 //卸载
将下载的文件进行解压:
tar -xf mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar
按顺序依次安装:
1. rpm -ivh mysql-community-common-5.7.12-1.el6.x86_64.rpm
2. rpm -ivh mysql-community-libs-5.7.12-1.el6.x86_64.rpm
3. rpm -ivh mysql-community-devel-5.7.12-1.el6.x86_64.rpm
4. rpm -ivh mysql-community-client-5.7.12-1.el6.x86_64.rpm
5. rpm -ivh mysql-community-server-5.7.12-1.el6.x86_64.rpm
如果出现这种报错:
file /usr/lib64/mysql/libmysqlclient.so.16.0.0 from install of mysql-libs-5.1.61-4.el6.x86_64 conflicts with file from package Percona-Server-shared-51-5.1.71-rel14.9.589.rhel6.x86_64
file /usr/lib64/mysql/libmysqlclient_r.so.16.0.0 from install of mysql-libs-5.1.61-4.el6.x86_64 conflicts with file from package Percona-Server-shared-51-5.1.71-rel14.9.589.rhel6.x86_64解决方法:yum -y remove Percona-Server-shared-51-5.1.71-rel14.9.589.rhel6.x86_64然后继续安装
service mysqld start ————————》启动服务
grep 'temporary password' /var/log/mysqld.log ————————》获取初始密码
mysql>set global validate_password_policy=0; ——————》更改密码策略,默认1表示必须符合长度,且必须含有数字,小写或大写字母,特殊字符
mysql>set global validate_password_length=4; ——————》更改密码长度,表示密码最小长度为4
mysql>SET PASSWORD FOR 'root'@'localhost'=PASSWORD('1234567'); ——————》设置密码
vim /etc/my.cnf ————》启动binlog日志
[mysqld]
log_bin=mysql-bin
server_id=1
MySQL设置密码的三种方法:
其设置密码有三种方法:
a. ./mysqladmin -u root -p oldpassword newpasswd(记住这个命令是在/usr/local/mysql/bin中外部命令)
b. SET PASSWORD FOR root=PASSWORD(’new password’);(对登录数据库后这种方式)
c. UPDATE user SET password=PASSWORD(”new password”) WHERE user=’root’; (对登录数据库后这种方式)
*********************************************************************************
卸载mysql的方法:
首先停用mysql: service mysqld stop
第一步:卸载所有mysql包
[root@iZbp1ddkszxcmrqic0imjwZ ~]# rpm -qa | grep mysql
mysql-community-common-5.7.21-1.el6.x86_64
mysql-community-devel-5.7.21-1.el6.x86_64
mysql-community-server-5.7.21-1.el6.x86_64
mysql-community-libs-5.7.21-1.el6.x86_64
mysql-community-client-5.7.21-1.el6.x86_64
卸载命令: rpm -e --nodeps mysql包
第二步:卸载mysql所有目录文件
[root@iZbp1ddkszxcmrqic0imjwZ ~]# find / -name mysql
/usr/share/mysql
/usr/include/mysql
/usr/include/mysql/mysql
/usr/bin/mysql
/usr/lib64/mysql
/root/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/etc/logrotate.d/mysql
卸载命令: rm -rf mysql路径
第三步:卸载my.cnf. 和 /var/log/mysqld.log 文件
rm -rf /etc/my.cnf
ok. mysql卸载完成。。如果遇到本文中没有的错误,请及时留言和百度。