CentOS7多實例安裝mysq5.6二進制版本

1丶下載mysql,解壓,建立用戶,建立軟連接

test -d /tools || mkdir /tools ;cd /tools 
wget 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選項mysql

/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_dblinux

yum install -y perl-Module-Install.noarch
相關文章
相關標籤/搜索