mysql_multi的现实意义:
1:随着连接数上升,性能会下降,通过多实例来分流大量连接来提高性能。
2:做资源隔离
3:分库分表
mysql_multi是官方管理多实例的一个脚本,利用perl语言来编写的。
实验环境:
数据库版本:mysql-5.7.14
/data/mysql/mysql3306/{data, log, tmp}
/data/mysql/mysql3307/{data, log, tmp}
现在系统里面已经有了mysql3306这个版本了,我们直接安装一个3307即可。my3307.cnf配置文件可以copy my3306.cnf,修改关键部位即可。
初始化:
cd /uer/local/mysql
./bin/mysqld --defaults-file=/data/mysql3307/my3307.cnf --initialize
cat /data/mysq/mysql3307/data/error.log
现在我们要准备一个my.cnf文件,这个文件一定放在/etc/my.cnf下,且里面要有两个部分:[mysqld_mutli]和[mysqldN](N代表端口号)。
例如:
[mysql_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
log = /data/mysql/mysqld_multi.log
user = liumdev
password = liumdevadmin
[mysqld3306]
port = 3306
socket = /tmp/mysql3306.sock
datadir = /data/mysql/mysql3306/data
tmpdir = /data/mysql/mysql3306/tmp
server-id = 13306
log-bin = /data/mysql/mysql3306/log/mysql-bin
[mysqld3307]
port = 3307
socket = /tmp/mysql3307.sock
datadir = /data/mysql/mysql3307/data
tmpdir = /data/mysql/mysql3307/tmp
server-id = 13307
log-bin = /data/mysql/mysql3307/log/mysql-bin
这里注意,[mysqldN]里面配置的参数要在[mysqld]后面,这样后面的参数会覆盖前面的参数,好处是如果你想对单独的实例做一下参数调优的话可以自己设定,3306与3307之间是互不影响的。
启动:/usr/local/mysql/bin/mysql_multi start 3306
/usr/local/mysql/bin/mysqld_multi start
创建对应的用户并给与shuwdown权限:
create user 'liumdev'@'localhost' identfied by 'liumdevadmin';
grant shutdown on *.* to 'liumdev'@'localhost'; flush privileges;
查看账户:select user,host,authentication_string from mysql.user;
更改授权:update mysql.user set host='127.0.0.1' where user = 'liumdev';
关闭:/usr/local/mysql/bin/mysqld_multi stop
/usr/local/mysql/bin/mysqld_multi stop 3307
排错:
1:使用mysqld_multi stop 3307 报错 'access denied for .... (using password: yes)'?
这是因为5.6版本以后不允许在终端上输出明文密码导致,解决的话修改/usr/local/mysql/bin/mysqld_multi,更改:
my $com= join ' ', 'my_print_defaults -s', @defaults_options, $group;
2:注意关闭多实例的用户和密码是3306和3307上分别创建的,要两个账户必须是一样的。
3:5.7版本动态修改innodb_buffer_pool_size:set global innodb_buffer_pool_size=1000*1024*1024;