mysql 多实例

一.安装mysql

 

二.配置my.cnf

[mysqld3306]
port=3306
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql3306.sock
pid-file=/var/run/mysqld/mysqld3306.pid
log-error = /var/lib/mysql/error.log

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld3307]
port=3307
datadir=/var/lib/mysql3307
socket=/var/lib/mysql3307/mysql3307.sock
pid-file=/var/run/mysqld/mysqld3307.pid
log-error = /var/lib/mysql3307/error.log

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


[mysqld3308]
port=3308
datadir=/var/lib/mysql3308
socket=/var/lib/mysql3308/mysql3308.sock
pid-file=/var/run/mysqld/mysqld3308.pid
log-error = /var/lib/mysql3308/error.log

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

  

三.创建和初始化数据目录

1.在/var/lib下创建mysql3307和mysql3308

2.赋予权限

chown mysql:mysql /var/lib/mysql3307
.....

  

3.初始化:

...
mysql_install_db --basedir=/usr/local/mysql/ --datadir=/var/lib/mysql3307 --defaults-file=/etc/my.cnf
...

  

四.多实例管理

启动全部实例:/usr/local/mysql/bin/mysqld_multi start
查看全部实例状态:/usr/local/mysql/bin/mysqld_multi report
启动单个实例:/usr/local/mysql/bin/mysqld_multi start 3306
停止单个实例:/usr/local/mysql/bin/mysqld_multi stop 3306
查看单个实例状态:/usr/local/mysql/bin/mysqld_multi report 3306

posted @ 2019-01-29 11:23  rorshach  阅读(374)  评论(0编辑  收藏  举报