CentOS7多实例安装mysq5.6二进制版本

时间:2021-06-22 21:00:04

1丶下载mysql,解压,创建用户,创建软链接

test -d /tools || mkdir /tools ;cd /tools 
http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
useradd  -s /sbin/nologin -M mysql
tar xf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz -C /usr/local
ln -sv /usr/local/mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql 

2丶创建目录以及授权

mkdir /data/{3306,3307,3308}/{data,log,tmp} -pv 
chown -R mysql.mysql /data 

3丶添加环境变量

echo 'export PATH=$PATH:/usr/local/mysql/bin' >>  /etc/profile  
export PATH=$PATH:/usr/local/mysql/bin

4丶创建my.cnf文件

#vim /etc/my.cnf 
[client]   
port=3306   
socket=/tmp/mysql.sock   
[mysqld_multi]   
mysqld = /usr/local/mysql/bin/mysqld_safe   
mysqladmin = /usr/local/mysql/bin/mysqladmin   
log = /data/mysqld_multi.log   
[mysqld]   
user=mysql   
basedir = /usr/local/mysql   
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES   
[mysqld3306]   
mysqld=mysqld   
mysqladmin=mysqladmin   
datadir=/data/3306/data   
port=3306   
server_id=3306   
socket=/tmp/mysql_3306.sock   
log-output=file   
slow_query_log = 1   
long_query_time = 1   
slow_query_log_file = /data/3306/log/slow.log   
log-error = /data/3306/log/error.log   
binlog_format = mixed   
log-bin = /data/3306/log/mysql3306_bin   
character-set-server=utf8
[mysqld3307]   
mysqld=mysqld   
mysqladmin=mysqladmin   
datadir=/data/3307/data   
port=3307   
server_id=3307   
socket=/tmp/mysql_3307.sock   
log-output=file   
slow_query_log = 1   
long_query_time = 1  
slow_query_log_file = /data/3307/log/slow.log   
log-error = /data/3307/log/error.log   
binlog_format = mixed   
log-bin = /data/3307/log/mysql3307_bin 
character-set-server=utf8
[mysqld3308]   
mysqld=mysqld   
mysqladmin=mysqladmin   
datadir=/data/3308/data   
port=3308   
server_id=3308   
socket=/tmp/mysql_3308.sock   
log-output=file   
slow_query_log = 1   
long_query_time = 1  
slow_query_log_file = /data/3308/log/slow.log   
log-error = /data/3308/log/error.log   
#binlog_format = mixed   
#log-bin = /data/3308/log/mysql3308_bin 
character-set-server=utf8

5丶初始化mysql

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306/data --defaults-file=/etc/my.cnf 
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3307/data --defaults-file=/etc/my.cnf 
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3308/data --defaults-file=/etc/my.cnf 

6丶使用mysqld_multi进行多实例管理

启动全部实例:/usr/local/mysql/bin/mysqld_multi start  
查看全部实例状态:/usr/local/mysql/bin/mysqld_multi report  
启动单个实例:/usr/local/mysql/bin/mysqld_multi start 3306  
停止单个实例:/usr/local/mysql/bin/mysqld_multi stop 3306  
查看单个实例状态:/usr/local/mysql/bin/mysqld_multi report 3306

7丶修改默认密码

mysqladmin -uroot   -S /tmp/mysql_3306.sock  password 'redhat123'
mysqladmin -uroot   -S /tmp/mysql_3307.sock  password 'redhat123'
mysqladmin -uroot   -S /tmp/mysql_3308.sock  password 'redhat123'

注意:如果添加了默认密码使用mysqld_multi管理的话需要使用--password选项

/usr/local/mysql/bin/mysqld_multi start 3306  --password=redhat 

8丶安装报错

报错1:FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db

yum install -y perl-Module-Install.noarch