背景:MYSQL多实例配置、dc提到在实际开发中,其实在生产环境上也有类似的运用,因多种原因,1.存储技术飞速发展,IO不再是瓶颈 2.MySQL对多核CPU利用率低 3.NUMA对MySQL性能的影响等,链接在:http://blog.csdn.net/hylongsuny/article/details/7892488 。
在实际的开发过程中,可能会需要在一台服务器上部署多个MYSQL实例,那建议使用MYSQL官方的解决方案 mysqld_multi
1.修改my.cnf
如一个定义两个实例的参考配置:
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = your_user
password = your_password
[mysqld1]
datadir = /data/db/my1
#连接
port = 3306
socket = /tmp/mysql3306.sock
#binlog
log-bin=/data/db/mylog1/mysql-bin
binlog_format=mixed
binlog_cache_size = 32M
expire_logs_days = 30
[mysqld2]
datadir = /data/db/my2
#连接
port = 3307
socket = /tmp/mysql3307.sock
#binlog
log-bin=/data/db/mylog2/mysql-bin
binlog_format=mixed
binlog_cache_size = 32M
expire_logs_days = 3
2.创建数据目录
mkdir -p /data/db/my21
mkdir -p /data/db/my2
chown mysql.mysql /data/db/my1 -R
chown mysql.mysql /data/db/my2 -R
3.初始化DB
/usr/local/mysql/scripts/mysql_install_db --datadir=/data/db/my1/ -uroot (mysql_install_db也是MYSQL官方自带工具)
/usr/local/mysql/scripts/mysql_install_db --datadir=/data/db/my2/ -uroot
chown mysql.mysql /data/db/my1/ -R
chown mysql.mysql /data/db/my2/ -R
4. 安装工具
cp /usr/local/mysql/bin/my_print_defaults /usr/bin/
cp /usr/local/mysql/bin/mysqld_multi /usr/bin/
5.创建、授权用户
CREATE USER "your_user"@"192.168.1.%" IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON *.* TO "your_user"@"192.168.1.%";
flush privileges;
至此,mysql多实例配置已经完毕。我们看到多个不同的MYSQL实例是共用my.cnf的。多实例命令行管理:
1.mysql启动
mysqld_multi start 1 启动实例1
mysqld_multi start 1-2 启动实例1,2
2.mysql重启
mysqld_multi restart 1 重启实例1
mysqld_multi restart 1-2 重启实例1,2
3.mysql关闭
mysqld_multi stop 1 关闭实例1
mysqld_multi stop 1-2 关闭实例1,2
4.命令行登陆实例2
mysql -u your_user -p your_password -P3307 -S /tmp/mysql3307.sock
摘自Dc(施俊伟)兄弟的唐品blog:
http://www.dcshi.com/?p=410#more-410
在实际的开发过程中,可能会需要在一台服务器上部署多个MYSQL实例,那建议使用MYSQL官方的解决方案 mysqld_multi
1.修改my.cnf
如一个定义两个实例的参考配置:
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = your_user
password = your_password
[mysqld1]
datadir = /data/db/my1
#连接
port = 3306
socket = /tmp/mysql3306.sock
#binlog
log-bin=/data/db/mylog1/mysql-bin
binlog_format=mixed
binlog_cache_size = 32M
expire_logs_days = 30
[mysqld2]
datadir = /data/db/my2
#连接
port = 3307
socket = /tmp/mysql3307.sock
#binlog
log-bin=/data/db/mylog2/mysql-bin
binlog_format=mixed
binlog_cache_size = 32M
expire_logs_days = 3
2.创建数据目录
mkdir -p /data/db/my21
mkdir -p /data/db/my2
chown mysql.mysql /data/db/my1 -R
chown mysql.mysql /data/db/my2 -R
3.初始化DB
/usr/local/mysql/scripts/mysql_install_db --datadir=/data/db/my1/ -uroot (mysql_install_db也是MYSQL官方自带工具)
/usr/local/mysql/scripts/mysql_install_db --datadir=/data/db/my2/ -uroot
chown mysql.mysql /data/db/my1/ -R
chown mysql.mysql /data/db/my2/ -R
4. 安装工具
cp /usr/local/mysql/bin/my_print_defaults /usr/bin/
cp /usr/local/mysql/bin/mysqld_multi /usr/bin/
5.创建、授权用户
CREATE USER "your_user"@"192.168.1.%" IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON *.* TO "your_user"@"192.168.1.%";
flush privileges;
至此,mysql多实例配置已经完毕。我们看到多个不同的MYSQL实例是共用my.cnf的。多实例命令行管理:
1.mysql启动
mysqld_multi start 1 启动实例1
mysqld_multi start 1-2 启动实例1,2
2.mysql重启
mysqld_multi restart 1 重启实例1
mysqld_multi restart 1-2 重启实例1,2
3.mysql关闭
mysqld_multi stop 1 关闭实例1
mysqld_multi stop 1-2 关闭实例1,2
4.命令行登陆实例2
mysql -u your_user -p your_password -P3307 -S /tmp/mysql3307.sock
摘自Dc(施俊伟)兄弟的唐品blog:
http://www.dcshi.com/?p=410#more-410
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/7495/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表