1、卸载mariadb
查看是否有默认的mariadbrpm -qa|grep mariadb
如果有,卸载rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
,然后删除etc目录下的my.cnfrm -rf /etc/my.cnf
(注意这里需要确定tar包里是否有默认的cnf文件,在support-files路径下的my-default.cnf,如果没有,建议直接修改这里的cnf文件)
2、下载tar包
下载之前,先检查是否安装过MySQLrpm -qa | grep mysql
,如果安装过,先卸载rpm -e xxx(xxx代表要删除的文件全名)
官网地址https://dev.mysql.com/downloads/mysql/
,选择Red Hat Linux操作系统,点击Looking for the latest GA version
,下载tar包即可
百度云地址:链接:https://pan.baidu.com/s/15UNu-8IhilKFb88d6Pd_MA?pwd=d38w 提取码:d38w
3、安装
先解压tar包得到对应的tar.gz压缩包
tar -xvf mysql-5.7.40-el7-x86_64.tar
然后解压mysql-5.7.40-el7-x86_64.tar.gz
这个包,tar -zxvf package/mysql-5.7.40-el7-x86_64.tar.gz
,得到如下文件
将mysql-5.7.40-el7-x86_64文件夹移动mv mysql-5.7.40-el7-x86_64 /usr/local
,重命名mv /usr/local/mysql-5.7.40-el7-x86_64/ /usr/local/mysql
,新建data目录mkdir /usr/local/mysql/data
,添加mysql用户组groupadd mysql
,添加mysql用户useradd mysql -g mysql
,将mysql的所有者改为mysqlchown -R mysql.mysql /usr/local/mysql
,安装(切换到mysql用户执行)/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
,这里如果出现
使用/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
,安装成功如图所示
会生成一个临时密码,这个一定要记好yYG+Ugzd.2ZZ
,编辑/etc/my.cnf文件
,内容如下所示
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
将mysql加入服务cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
,设置开机自启chkconfig mysql on
,启动MySQLservice mysql start
,然后连接MySQL.bin//mysql -u root -p
,输入上面的随机密码,连接成功。重置密码ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
,刷新flush privileges;
,再次重连,密码输入修改后的密码,连接成功。设置远程连接update user set host='%' where user ='root';
,刷新flush privileges;
至此,MySQl就安装成功了。