1.编译安装MySQL
如果有老的MySQL或Maridb,则要先卸载
[root@monitor ~]# systemctl stop mysqld
[root@monitor~]# rpm -qa | egrep -i 'mysql|maria'[root@monitor~]# rpm -qa | egrep -i 'mysql|maria'mariadb-libs-5.5.56-2.el7.x86_64
# 而实际这个mariadb-libs-5.5.56-2.el7.x86_64不需要卸载没有关系。
[root@monitor~]# rpm -e --nodeps +包名1 包名2 .....
# 删除老版本mysql的开发头文件和库
rm-rf /usr/lib/mysql
rm-rf /usr/include/mysql
# 注意:卸载后/var/lib/mysql中的数据及/etc/my.cnf不会删除,如果确定没用后就手工删除
rm-rf /etc/my.cnf
rm-rf /var/lib/mysql
下载安装配置
# 下载
[root@monitor~]# wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.22-el7-x86_64.tar.gz -P /usr/local/ #下载慢的话通过浏览器下载后再传上去
# 解压添加用户和环境变量
[root@monitor~]#
mkdir-p /usr/local/mysql &&\
cd/usr/local/ &&\
tar-xzvf mysql-5.7.22-el7-x86_64.tar.gz &&\
cp-arf mysql-5.7.22-el7-x86_64/*/usr/local/mysql/ && \
cd /usr/local/mysql/ && \
mkdir data && \
mkdir log && \
echo "export PATH=\$PATH:/usr/local/mysql/bin" >> /etc/profile && \
source /etc/profile && \
groupadd mysql && \
useradd -r -g mysql -s /bin/false mysql
# 查看目录
[root@monitor mysql]# pwd
/usr/local/mysql
[root@monitor mysql]# ll
total 36
drwxr-xr-x 2 root root 4096 Jan 4 11:07 bin
-rw-r--r-- 1 7161 31415 17987 Mar 4 2018 COPYING
drwxr-xr-x 2 root root 6 Jan 4 11:08 data
drwxr-xr-x 2 root root 55 Jan 4 11:07 docs
drwxr-xr-x 3 root root 4096 Jan 4 11:07 include
drwxr-xr-x 5 root root 229 Jan 4 11:07 lib
drwxr-xr-x 2 root root 6 Jan 4 11:08 log
drwxr-xr-x 4 root root 30 Jan 4 11:07 man
-rw-r--r-- 1 7161 31415 2478 Mar 4 2018 README
drwxr-xr-x 28 root root 4096 Jan 4 11:07 share
drwxr-xr-x 2 root root 90 Jan 4 11:07 support-files
# 更新配置文件
[root@monitor mysql]#
cp -arf /etc/my.cnf /etc/my.cnf.bak`date +%F`
cat >/etc/my.cnf << EOF
[client]
socket=/usr/local/mysql/mysql.sock
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
pid-file