mysql多实例安装

2018/07 作者:ihunter 0 0


groupadd mysql

useradd -r -g mysql mysql

mkdir -pv /home/data/mysql_330{1..9}

mkdir -pv /home/data/mysql_331{0..4}

chown -R mysql:mysql /home/data

mkdir /home/data/logs

chown -R mysql:mysql /home/data/logs/

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3301

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3302

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3303

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3304

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3305

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3306

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3307

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3308

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3309

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3310

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3311

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3312

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3313

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql_3314

vim /etc/my.cnf

--

[mysqld_multi]

mysqld = /usr/local/mysql/bin/mysqld_safe

mysqladmin =/usr/local/mysql/bin/mysqladmin

log =/home/data/logs/mysqld_multi.log

[mysqld1]

basedir=/usr/local/mysql

datadir=/home/data/mysql_3301

port=3301

server_id=1

socket=/home/data/mysql_3301/mysql.sock

symbolic-links=0

character_set_server=utf8

pid-file=/home/data/mysql_3301/mysql.pid

wait_timeout=1814400

max_connections = 1500

[mysqld2]

basedir=/usr/local/mysql

datadir=/home/data/mysql_3302

port=3302

server_id=2

socket=/home/data/mysql_3302/mysql.sock

symbolic-links=0

character_set_server=utf8

pid-file=/home/data/mysql_3302/mysql.pid

wait_timeout=1814400

max_connections = 1500

[mysqld3]

basedir=/usr/local/mysql

datadir=/home/data/mysql_3303

port=3303

server_id=3

socket=/home/data/mysql_3303/mysql.sock

symbolic-links=0

character_set_server=utf8

pid-file=/home/data/mysql_3303/mysql.pid

wait_timeout=1814400

max_connections = 1500

[mysqld4]

basedir=/usr/local/mysql

datadir=/home/data/mysql_3304

port=3304

server_id=4

socket=/home/data/mysql_3304/mysql.sock

symbolic-links=0

character_set_server=utf8

pid-file=/home/data/mysql_3304/mysql.pid

wait_timeout=1814400

max_connections = 1500

[mysqld5]

basedir=/usr/local/mysql

datadir=/home/data/mysql_3305

port=3305

server_id=5

socket=/home/data/mysql_3305/mysql.sock

symbolic-links=0

character_set_server=utf8

pid-file=/home/data/mysql_3305/mysql.pid

wait_timeout=1814400

max_connections = 1500

[mysqld6]

basedir=/usr/local/mysql

datadir=/home/data/mysql_3306

port=3306

server_id=6

socket=/home/data/mysql_3306/mysql.sock

symbolic-links=0

character_set_server=utf8

pid-file=/home/data/mysql_3306/mysql.pid

wait_timeout=1814400

max_connections = 1500

[mysqld7]

basedir=/usr/local/mysql

datadir=/home/data/mysql_3307

port=3307

server_id=7

socket=/home/data/mysql_3307/mysql.sock

symbolic-links=0

character_set_server=utf8

pid-file=/home/data/mysql_3307/mysql.pid

wait_timeout=1814400

max_connections = 1500

[mysqld8]

basedir=/usr/local/mysql

datadir=/home/data/mysql_3308

port=3308

server_id=8

socket=/home/data/mysql_3308/mysql.sock

symbolic-links=0

character_set_server=utf8

pid-file=/home/data/mysql_3308/mysql.pid

wait_timeout=1814400

max_connections = 1500

[mysqld9]

basedir=/usr/local/mysql

datadir=/home/data/mysql_3309

port=3309

server_id=9

socket=/home/data/mysql_3309/mysql.sock

symbolic-links=0

character_set_server=utf8

pid-file=/home/data/mysql_3309/mysql.pid

wait_timeout=1814400

max_connections = 1500

[mysqld10]

basedir=/usr/local/mysql

datadir=/home/data/mysql_3310

port=3310

server_id=10

socket=/home/data/mysql_3310/mysql.sock

symbolic-links=0

character_set_server=utf8

pid-file=/home/data/mysql_3310/mysql.pid

wait_timeout=1814400

max_connections = 1500

[mysqld11]

basedir=/usr/local/mysql

datadir=/home/data/mysql_3311

port=3311

server_id=11

socket=/home/data/mysql_3311/mysql.sock

symbolic-links=0

character_set_server=utf8

pid-file=/home/data/mysql_3311/mysql.pid

wait_timeout=1814400

max_connections = 1500

[mysqld12]

basedir=/usr/local/mysql

datadir=/home/data/mysql_3312

port=3312

server_id=12

socket=/home/data/mysql_3312/mysql.sock

symbolic-links=0

character_set_server=utf8

pid-file=/home/data/mysql_3312/mysql.pid

wait_timeout=1814400

max_connections = 1500

[mysqld13]

basedir=/usr/local/mysql

datadir=/home/data/mysql_3313

port=3313

server_id=13

socket=/home/data/mysql_3313/mysql.sock

symbolic-links=0

character_set_server=utf8

pid-file=/home/data/mysql_3313/mysql.pid

wait_timeout=1814400

max_connections = 1500

[mysqld14]

basedir=/usr/local/mysql

datadir=/home/data/mysql_3314

port=3314

server_id=14

socket=/home/data/mysql_3314/mysql.sock

symbolic-links=0

character_set_server=utf8

pid-file=/home/data/mysql_3314/mysql.pid

wait_timeout=1814400

max_connections = 1500

--//启用多实例数据库

/etc/init.d/mysqld_multi start 1,2,3,4,5,6,7,8,9,10,11,12,13,14

mysql --socket=/home/data/mysql_3301/mysql.sock

mysql --socket=/home/data/mysql_3302/mysql.sock

...

--//查看多实例

set password =password('bnh1923');

grant all on *.* to 'root'@'%' IDENTIFIED BY 'bnh1923' with grant option;

flush privileges;

--//关闭服务

mysqladmin -uroot -pbnh1923 --socket=/home/data/mysql_3314/mysql.sock shutdown

--//查看多实例

mysqld_multi --defaults-extra-file=/etc/my.cnf report

停止多实例: mysqld_multi--defaults-extra-file=/etc/my.cnf stop 1,2,3

各自登录mysql实例:

需要指定启动的socket就可以登录到各自的mysql实例. mysql --socket=/usr/local/mysql3308/mysql.sock

查看已经启动的mysql实例: netstat -ntpl|grep 330

连接不同的实例,用port区分: mysql -uroot -p -P3307


赞(2) 更多分享

上篇: CentOS7yum安装Mysql多实例,并搭建Mycat
下篇: mysql忘记密码