MySQL多实例安装
1、配置3306实例
1.1、查询服务器上是否已经安装的mysql
[root@masterMySQL-5.6.25-1.el6.x86_64.rpm-bundle]# rpm -aq | grep mysql
mysql-server-5.1.66-2.el6_3.x86_64
mysql-libs-5.1.66-2.el6_3.x86_64
mysql-devel-5.1.66-2.el6_3.x86_64
qt-mysql-4.6.2-25.el6.x86_64
mysql-5.1.66-2.el6_3.x86_64
1.2、先卸载旧的版本
rpm -e mysql --nodeps --allmatches (不理会依赖关系,删除所有上一步查出来的mysql)
[root@master ~]#rpm -e mysql-server-5.1.66-2.el6_3.x86_64 --nodeps --allmatches
[root@master ~]#rpm -e mysql-libs-5.1.66-2.el6_3.x86_64 --nodeps --allmatches
[root@master ~]#rpm -e mysql-devel-5.1.66-2.el6_3.x86_64 --nodeps --allmatches
[root@master ~]#rpm -e qt-mysql-4.6.2-25.el6.x86_64 --nodeps --allmatches
[root@master ~]#rpm -e mysql --nodeps --allmatches
[root@master ~]#rpm -aq | grep mysql
1.3、安装软件
# rpm -ivfMySQL-server-5.6.25-1.el6.x86_64.rpm #MySQL服务端程序
# rpm -ivfMySQL-client-5.6.25-1.el6.x86_64.rpm #MySQL客户端程序
# rpm -ivfMySQL-devel-5.6.25-1.el6.x86_64.rpm #MySQL的库和头文件
# rpm -ivfMySQL-shared-5.6.25-1.el6.x86_64.rpm #MySQL的共享库
# rpm -ivfMySQL-shared-compat-5.6.25-1.el6.x86_64.rpm #RHEL兼容包
1.4、修改密码
#/etc/init.d/mysql stop
# mysqld_safe--skip-grant-tables &
# mysql-uroot -e "use mysql;update userset password=password('123456') where user='root' and host='localhost';";
# mysql-uroot -e"use mysql;update user sethost='%' where user='root' and host='localhost';flush privileges;";
1.5、修改配置文件
[root@mastermysql]#service mysql stop
[root@mastermysql]# vi /usr/my.cnf
[client]
default-character-set=utf8
port =3306
socket =/var/lib/mysql/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
replicate-ignore-db=mysql
binlog-ignore-db=mysql
binlog-ignore-db=performance_schema
binlog-ignore-db=information_schema
character-set-server=utf8
user =mysql
port =3306
socket =/var/lib/mysql/mysql.sock
basedir =/usr
datadir =/var/lib/mysql
server-id= 1
default-storage-engine=InnoDB
binlog_format=mixed
open_files_limit = 10240
back_log= 600
max_connections= 1000
max_connect_errors= 6000
table_open_cache=614
external-locking= FALSE
max_allowed_packet= 32M
sort_buffer_size= 2M
join_buffer_size= 2M
thread_cache_size= 64
thread_concurrency= 8
query_cache_size= 64M
query_cache_limit= 4M
query_cache_min_res_unit= 2k
thread_stack= 192K
transaction_isolation= REPEATABLE-READ
tmp_table_size= 256M
max_heap_table_size= 256M
long_query_time= 1
slow_query_log=1
slow_query_log_file= /var/lib/mysql/mysql_slow_query.log
#log_long_format
log-error=/var/lib/mysql/master.err
pid-file=/var/lib/mysql/mysql.pid
log-bin =/var/lib/mysql/master-bin
log_bin_index=/var/lib/mysql/master-bin.index
relay-log=/var/lib/mysql/relay-bin
relay-log-info-file=/var/lib/mysql/relay-log.info
binlog_cache_size= 4M
max_binlog_cache_size= 50M
max_binlog_size= 512M
expire_logs_days= 7
key_buffer_size= 32M
read_buffer_size= 1M
read_rnd_buffer_size= 16M
bulk_insert_buffer_size= 64M
myisam_sort_buffer_size= 128M
myisam_max_sort_file_size= 10G
myisam_recover
skip-name-resolve
lower_case_table_names= 1
slave-skip-errors=1032,1062
innodb_additional_mem_pool_size= 16M
innodb_buffer_pool_size= 2048M
innodb_file_io_threads= 4
innodb_thread_concurrency= 8
innodb_flush_log_at_trx_commit= 1
innodb_log_buffer_size= 16M
innodb_log_file_size= 128M
innodb_log_files_in_group= 3
innodb_max_dirty_pages_pct= 90
innodb_lock_wait_timeout= 120
innodb_file_per_table= 0
[mysqldump]
quick
max_allowed_packet= 32M
[mysqld_safe]
log-error=/var/lib/mysql/mysql_master.err
pid-file=/var/lib/mysql/mysqld.pid
service mysqlstart
2、配置3307实例
2.1、建立3307目录存放数据:
[root@master ~]#mkdir /data/3307/mysql -p
[root@master ~]#cd /
[root@master /]#chown -R mysql.mysql data
[root@master /]#cd /data/3307/mysql
2.2、建立3307配置文件:
vi my.cnf
[client]
default-character-set=utf8
port = 3307
socket = /data/3307/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
character-set-server=utf8
user = mysql
port = 3307
socket = /data/3307/mysql.sock
basedir = /usr
datadir = /data/3307/mysql
binlog_format=mixed
open_files_limit = 10240
sync_binlog = 1
back_log = 600
max_connections = 3000
max_connect_errors = 6000
#table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 300
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 4M
query_cache_min_res_unit = 2k
#default_table_type = InnoDB
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 256M
max_heap_table_size = 256M
long_query_time = 1
slow_query_log=1
slow_query_log_file =/data/3307/mysql/mysql_slow_query.log
#log_long_format
log-error=/data/3307/mysql/error.log
#log-slow-queries=/data/3307/mysql/slow-log.log
pid-file=/data/3307/mysql/mysql.pid
log-bin = /data/3307/mysql/mysql-bin
relay-log=/data/3307/mysql/relay-bin
relay-log-info-file=/data/3307/mysql/relay-log.info
binlog_cache_size = 4M
max_binlog_cache_size = 50M
max_binlog_size = 512M
expire_logs_days = 7
key_buffer_size = 32M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
skip-name-resolve
lower_case_table_names = 1
slave-skip-errors=1032,1062
#repicate-ignore-db=mysql
server-id = 11
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 2048M
#innodb_data_file_path =ibdata1:1024M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 16M
innodb_log_file_size = 1024M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 32M
[mysqld_safe]
log-error=/data/3307/mysql/mysql_master.err
pid-file=/data/3307/mysql/mysqld.pid
修改配置参数的权限
[root@mastermysql]# chown mysql.mysql my.cnf
[root@mastermysql]# /usr/bin/mysql_install_db --defaults-file=/data/3307/mysql/my.cnf--user=mysql --basedir=/usr --datadir=/data/3307/mysql/
[root@mastermysql]# /usr/bin/mysqld_safe --defaults-file=/data/3307/mysql/my.cnf--user=mysql --basedir=/usr --datadir=/data/3307/mysql/ &
2.3、查看端口号:
netstat -nat|grep 330
2.4、修改密码:
mysqladmin-uroot password '123456' -S /data/3307/mysql.sock
本文转自 corasql 51CTO博客,原文链接:http://blog.51cto.com/corasql/1695404,如需转载请自行联系原作者