温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

mysql多实例部署

发布时间:2020-08-08 23:37:54 来源:ITPUB博客 阅读:172 作者:千寻ccxx 栏目:MySQL数据库
1.修改my.cnf
[mysql]

[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user =
password =

[mysqld1]
#explicit_defaults_for_timestamp=true
port = 3306
skip-name-resolve
server_id=1
datadir=/data/master
max_connections=3000
slow-query-log=on ##开启慢查询
slow-query-log-file=/var/log/mysql1/mysql-slow-queries.log
long_query_time=3
##开启二进制文件
log-bin=/data/master_binlog/mysql1_bin.log
log-bin-index=/data/master_binlog/binlog.index
binlog-do-db=ibuy
innodb_buffer_pool_size=2G #缓存
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_additional_mem_pool_size = 64M
socket=/var/lib/mysql/mysql3306.sock
pid-file=/data/master/mysql.pid
#query_cache_size = 128M #查询缓存,合适查操作比较多的数据库
symbolic-links=0
sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
log-error=/var/log/mysql1/mysqld.log
user=mysql




[mysqld2]
port=3307
server_id=2
explicit_defaults_for_timestamp=true
skip-name-resolve
datadir=/data/slave
max_connections=3000
slow-query-log=on ##开启慢查询
slow-query-log-file=/var/log/mysql2/mysql-slow-queries.log
long_query_time=3
log-bin=/data/slave_binlog/mysql_bin.log ##开启二进制文件
log-bin-index=/data/slave_binlog/binlog.index
binlog-do-db=ibuy
innodb_buffer_pool_size=3G #缓存
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_additional_mem_pool_size = 64M
socket=/var/lib/mysql/mysql3307.sock
pid-file=/data/slave/mysql.pid
#query_cache_size =512M #查询缓存,合适查操作比较多的数据库
symbolic-links=0
sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
log-error=/var/log/mysql2/mysqld.log
user=mysql

[mysqld_safe]
#max_allowed_packet=20480
#log-error=/var/log/mysql/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid

2.创建数据目录
		
  1. mkdir -p /data/master
  2. mkdir -p /data/slave
  3. mkdir -p /data/master_binlog
  4. mkdir -p /data/slave_binlog
  5. mkdir /var/log/mysql1
  6. mkdir /var/log/mysql2
  7. chown mysql.mysql /data/master -R
  8. chown mysql.mysql /data/slave -R
  9. chmod 777 /var/log/mysql1
  10. chmod 777 /var/log/mysql2
  11. chmod 777 /var/lib/mysql
3.初始化DB
/usr/local/mysql/scripts/mysql_install_db --datadir=/data/master 
/usr/local/mysql/scripts/mysql_install_db --datadir=/data/slave 
4. 安装工具 
	
  1. cp /usr/local/mysql/bin/my_print_defaults /usr/bin/
  2. cp /usr/local/mysql/bin/mysqld_multi /usr/bin
5.修改环境变量
#vim /etc/profile
PATH=$PATH:/usr/local/mysql/bin
export PATH


1.mysql启动

	
  1. mysqld_multi start 1 启动实例1
  2. mysqld_multi start 1-2 启动实例1,2

2.命令行登陆

	
  1. mysql -u your_user -p your_password -P3307 -S /tmp/mysql3307.sock
由于涉及权限问题,mysqld_multi不能控制关闭mysql多实例,自己写了个关闭脚本
#!/bin/bash
user=""
password=""
read -p "Please input mysqld ID 1-2:" ID
if [ "$ID" == "1" ]; then
#read -p "Please input mysqld port number 3306-3307:" port
/usr/local/mysql/bin/mysqladmin -u$user -p$password -S /var/lib/mysql/mysql3306.sock shutdown && echo "close mysqld master successful"
elif [ "$ID" == "2" ]; then
/usr/local/mysql/bin/mysqladmin -u$user -p$password -S /var/lib/mysql/mysql3307.sock shutdown && echo "close mysqld slave successful"
else
echo "Please input mysqld ID 1-2:"
fi
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI