centos同时运行mysql5.6和mysql5.7
一、准备
从mysql官网下载mysql5.6和mysql5.7
关闭防火墙,关闭selinux
创建mysql用户
~]# useradd mysql
二、安装
先安装mysql5.6
1.解压,并改名
~]# tar xf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz -C /opt
~]# cd /opt
~]# mv mysql-5.6.40-linux-glibc2.12-x86_64 mysql56
2.初始化mysql
~]# cd mysql56
~]# ./scripts/mysql_install_db --user=mysql --datadir=/opt/mysql56/data --basedir=/opt/mysql56
注:如果在安装的过程中出现
解决方法是安装autoconf库
执行命令:yum -y install autoconf
安装完成之后继续执行安装mysql的命令
这时候会在mysql中自动创建一个文件my.cng,编辑这个文件
[mysqld] basedir = /opt/mysql56 datadir = /opt/mysql56/data port = 3316 socket = /opt/mysql56/mysql.sock explicit_defaults_for_timestamp=true sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
3.运行启动mysql56
~]# ./bin/mysqld_safe --defaults-file=/opt/mysql56/my.cnf --user=root &
接下来安装mysql5.7
1.解压,并改名
~]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /opt
~]# cd /opt
~]# mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql57
2.编辑my.cnf
~]# vim /etc/my.cnf
[client] port = 3326 default-character-set = utf8 socket = /opt/mysql57/mysql.sock [mysql] port = 3326 socket = /opt/mysql57/mysql.sock [mysqld] bind-address = 0.0.0.0 log_error=/opt/mysql57/log/mysqld_error.log slow_query_log_file=/opt/mysql57/log/mysqld_slow.log general_log_file=/opt/mysql57/log/mysqld_gener.log basedir = /opt/mysql57 datadir = /opt/mysql57/data port = 3326 socket = /opt/mysql57/mysql.sock explicit_defaults_for_timestamp=true tmpdir = /opt/mysql57 pid-file = /opt/mysql57/mysqld.pid
~]# mkdir data log
~]# bin/mysqld --initialize --user=mysql --basedir=/opt/mysql57 --datadir=/opt/mysql57/data
~]# cat log/mysqld_error.log
记下红框中的密码,这个是mysql的root用户密码
~]# mv /etc/my.cnf ./
~]# bin/mysqld_safe --defaults-file=/opt/mysql57/my.cnf --user=root &
至此,CentOS中同时安装mysql5.6和mysql5.7完成!!!