一台服务器上面启动多个mysql事例(一看就会)
现在每台服务器上面都有相应的数据库,为了实现数据安全,采用主从复制进行备份,但是如果一对一的进行备份就太浪费资源,所以主库向一个数据库进行主从又在安全上没有保障,当这个库挂了,所有的备份也就挂了,而且管理起来也相当的不方便,所以我就选择使用mysql_multi实现一台机器上跑多台mysql,
一:首先在/etc/my.cnf配置文件中添加信息,分配好他们的进程号、占用端口号、数据存放路径、pid文件。
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
log = /app/log/mysqld_multi.log
user = root
password = meiyu#super^^
[mysqld1]
socket = /app/mysql1/mysqld_3306.sock
port = 3306
pid-file = /app/mysql1/mysqld3306.pid
datadir = /app/mysql1
log-error = /app/mysql1/err-3306.log
server-id=373306
[mysqld2]
socket = /app/mysql2/mysqld_3307.sock
port = 3307
pid-file = /app/mysql2/mysqld3307.pid
datadir = /app/mysql2
log-error = /app/mysql2/err-3307.log
server-id=373307
[mysqld3]
socket = /app/mysql3/mysqld_3308.sock
port = 3308
pid-file = /app/mysql3/mysqld3308.pid
datadir = /app/mysql3
log-error = /app/mysql3/err-3308.log
server-id=373308
character-set-server=utf8
innodb_file_per_table = 1
query_cache_type = 0
max_prepared_stmt_count = 1000000
table_definition_cache = 1000
innodb_flush_method=O_DIRECT
innodb_adaptive_flushing=1
innodb_io_capacity=10000
max_connections = 10000
max_connect_errors = 10000000000
table_open_cache = 500
max_allowed_packet = 16M
#binlog_cache_size = 1M
max_heap_table_size = 64M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 10000
thread_concurrency = 16
query_cache_size = 0
query_cache_limit = 0
ft_min_word_len = 4
default-storage-engine = INNODB
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 64M
#log-bin=mysql-bin
#binlog_format=mixed
slow_query_log
log-queries-not-using-indexes
long_query_time = 1
key_buffer_size = 16M
bulk_insert_buffer_size = 8M
#myisam_sort_buffer_size = 16M
#myisam_max_sort_file_size = 3G
#myisam_repair_threads = 1
#myisam_recover
innodb_additional_mem_pool_size = 8M
innodb_buffer_pool_size = 3G
innodb_data_file_path = ibdata1:512M:autoextend
innodb_autoextend_increment = 100
innodb_write_io_threads = 16
innodb_read_io_threads = 8
innodb_thread_concurrency = 0
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 1M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 60
innodb_lock_wait_timeout = 120
skip_name_resolve
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
#key_buffer_size = 512M
#sort_buffer_size = 512M
#read_buffer = 8M
#write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
在每个添加的mysql添加上他们的路径,给他们添加权限(很重要的)
二:做完这些简单的配置之后,我们就要创建实例
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --datadir=/app/mysql1 --user=mysql --basedir=/usr/local/mysql/
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --datadir=/app/mysql2 --user=mysql --basedir=/usr/local/mysql/
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --datadir=/app/mysql3 --user=mysql --basedir=/usr/local/mysql/
创建完事例,之后我们在启动一下我们的配置文件
/usr/local/mysql/bin/mysqld_multi start 1,2,3
启动事例完之后,我们就可以查看我们的配置的节点有没有报错,是否能成功
/app/mysql/bin/mysqld_multi report
我们再查看一下端口号是否起来,netstat –tnlp
检验节点没有错误,端口正常启动,最后一步我们看一下mysq事例是否能登陆进去
mysql -uroot -p -S /tmp/mysql.sock01
这样把多个事例的配置文件放在了一个里面,在做主从的话就不怎么方便了,如果我想做主从的话,在第一步设置的时候就把配置文件单独存放一个路径。