码迷,mamicode.com
首页 > 数据库 > 详细

mysql多实例的配置

时间:2014-12-18 22:04:02      阅读:337      评论:0      收藏:0      [点我收藏+]

标签:style   ar   io   color   sp   for   on   文件   div   

1、创建多实例的目录:
mkdir -p /data/mysql/mysql_3307/{data,tmp,logs}
mkdir -p /data/mysql/mysql_3308/{data,tmp,logs}
 
2、修改my.cnf的配置文件
vi /data/mysql/mysql_3306/my3306.cnf 
#my.cnf
[client]
port            = 3306
socket          = /data/mysql/mysql_3306/tmp/mysql_3306.sock
 
[mysql]
prompt=[3306]>
#tee=/data/mysql/mysql_3306/data/query.log
no-auto-rehash
 
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql/mysql_3306/data
port = 3306
socket = /data/mysql/mysql_3306/tmp/mysql_3306.sock
event_scheduler = 0
 
#timeout
interactive_timeout = 300
wait_timeout = 300
 
#character set
character-set-server = utf8
 
#open_files_limit = 65535
max_connections = 100
max_connect_errors = 100000
 
skip-name-resolve = 1
#logs
log-output=file
slow_query_log = 1
slow_query_log_file = slow.log
log-error = /data/mysql/mysql_3306/data/error.log
log_warnings = 2
pid-file = mysql.pid
long_query_time = 1
#log-slow-admin-statements = 1
#log-queries-not-using-indexes = 1
log-slow-slave-statements = 1
 
 
#binlog
binlog_format = mixed
server-id = 203306
log-bin = /data/mysql/mysql_3306/logs/mybinlog
binlog_cache_size = 4M
max_binlog_size = 1G
max_binlog_cache_size = 2G
sync_binlog = 0
expire_logs_days = 10
 
#relay log
skip_slave_start = 1
max_relay_log_size = 1G
relay_log_purge = 1
relay_log_recovery = 1
log_slave_updates
#slave-skip-errors=1032,1053,1062
 
explicit_defaults_for_timestamp=1
#buffers & cache
table_open_cache = 2048
table_definition_cache = 2048
table_open_cache = 2048
max_heap_table_size = 96M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 256
query_cache_size = 0
query_cache_type = 0
query_cache_limit = 256K
query_cache_min_res_unit = 512
thread_stack = 192K
tmp_table_size = 96M
key_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 32M
 
#myisam
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
 
#innodb
innodb_buffer_pool_size = 100M
innodb_buffer_pool_instances = 1
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 64M
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 50
innodb_file_per_table = 1
innodb_rollback_on_timeout
innodb_status_file = 1
innodb_io_capacity = 2000
transaction_isolation = READ-COMMITTED
innodb_flush_method = O_DIRECT
 
[mysqld_safe]
open_file_limit = 65535
 
 
 
 
3、复制配置文件到其他实例的目录:
cp /data/mysql/mysql_3306/my3306.cnf /data/mysql/mysql_3307/my3307.cnf
cp /data/mysql/mysql_3306/my3306.cnf /data/mysql/mysql_3308/my3308.cnf
 
 
 
4、修改其他实例的目录路径
vi /data/mysql/mysql_3307/my3307.cnf
:%s/3306/3307/g
 
vi /data/mysql/mysql_3308/my3308.cnf
:%s/3306/3308/g
 
 
 
5、赋予权限:
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /data
chown -R mysql:mysql /opt/mysql
 
 
 
6、多实例的初始化:
cd  /usr/local/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/mysql_3306/data --defaults-file=/data/mysql/mysql_3306/my3306.cnf
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/mysql_3307/data --defaults-file=/data/mysql/mysql_3307/my3307.cnf
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/mysql_3308/data --defaults-file=/data/mysql/mysql_3308/my3308.cnf
 
 
7、启动进程:
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql_3306/my3306.cnf &
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql_3307/my3307.cnf &
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql_3308/my3308.cnf &
 
 
8、查看指定文件目录是否存在:(每个实例在启动前都要查看)
ll /data/mysql/mysql_3306/tmp
srwxrwxrwx 1 mysql mysql 0 Dec 18 07:08 mysql_3306.sock
 
ll /data/mysql/mysql_3307/tmp
srwxrwxrwx 1 mysql mysql 0 Dec 18 07:10 mysql_3307.sock
 
ll /data/mysql/mysql_3308/tmp
srwxrwxrwx 1 mysql mysql 0 Dec 18 07:22 mysql_3308.sock
 
 
9、多实例的登陆方式:
mysql --protocol=tcp -h 127.0.0.1 -uroot -P3306  --socket=/data/mysql/mysql_3306/tmp/mysql_3306.sock
mysql --protocol=tcp -h 127.0.0.1 -uroot -P3307  --socket=/data/mysql/mysql_3307/tmp/mysql_3307.sock
mysql --protocol=tcp -h 127.0.0.1 -uroot -P3308  --socket=/data/mysql/mysql_3308/tmp/mysql_3308.sock
 
 
10、关闭mysql:
mysqladmin -S   /data/mysql/mysql_3308/tmp/mysql_3306.sock shutdown
mysqladmin -S   /data/mysql/mysql_3308/tmp/mysql_3307.sock shutdown
mysqladmin -S   /data/mysql/mysql_3308/tmp/mysql_3308.sock shutdown
 
 
 
 
 
=================================================
在试验过程中出现的问题:
1、本来想在一个配置文件里创建多个实例,但是在初始化的时候发现error-log,bin-log,socket这些文件不能创建在指定目录。
2、配置参数如下:
也可以在/etc/my.cnf下进行多实例配置,在配置文件底部添加如下:
#端口号为3306的实例特殊配置
[mysqld3306]
port =3306
server-id=2003306
#指定本实例相应版本的basedir和datadir
basedir= /usr/local/mysql
datadir = /data/mysql/mysql_3306/data
log-bin = /data/mysql/mysql_3306/logs/mybinlog
log-error = /data/mysql/mysql_3306/data/error.log
socket = /data/mysql/mysql_3306/tmp/mysql_3306.sock
pid-file = /data/mysql/mysql_3306/tmp/mysql3306.pid
#重新配置这几个选项,不与全局配置一样,会直接覆盖上面的全局设置
innodb_buffer_pool_size = 100m
transaction_isolation = REPEATABLE-READ
 
[mysqld3307]
port=3307
server-id=2003307
#binlog-do-db=db01
basedir= /usr/local/mysql
datadir = /data/mysql/mysql_3307/data
log-bin = /data/mysql/mysql_3307/logs/mybinlog
log-error = /data/mysql/mysql_3307/data/error.log
socket = /data/mysql/mysql_3307/tmp/mysql_3307.sock
pid-file = /data/mysql/mysql_3307/tmp/mysql3307.pid
#重新配置这几个选项,不与全局配置一样,会直接覆盖上面的全局设置
innodb_buffer_pool_size = 100m
innodb_flush_log_at_trx_commit = 2
sync_binlog = 0
 
[mysqld3308]
port=3308
server-id=2003308
#binlog-do-db=db01
basedir= /usr/local/mysql
datadir = /data/mysql/mysql_3308/data
log-bin = /data/mysql/mysql_3308/logs/mybinlog
log-error = /data/mysql/mysql_3308/data/error.log
socket = /data/mysql/mysql_3308/tmp/mysql_3308.sock
pid-file = /data/mysql/mysql_3308/tmp/mysql3308.pid
#重新配置这几个选项,不与全局配置一样,会直接覆盖上面的全局设置
innodb_buffer_pool_size = 100m
innodb_flush_log_at_trx_commit = 2
sync_binlog = 0
 
3、那位大神路过可以指点指点。

mysql多实例的配置

标签:style   ar   io   color   sp   for   on   文件   div   

原文地址:http://www.cnblogs.com/abobo/p/4172760.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!