1.复制cnf文件,
cp my.cnf my_muti.cnf
2.编辑my_muti.cnf文件
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user=mysql
[mysqld1]
port = 3306
socket = /tmp/mysql3306.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data3306
log-bin=mysql-bin
[mysqld2]
port = 3307
socket = /tmp/mysql3307.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data3307
log-bin=mysql-bin
必须初始化数据库目录:
- shell>cd /usr/local/mysql/;./scripts/mysql_install_db --datadir=/usr/local/mysql/data3307/ --user=mysql
-
- shell>cd /usr/local/mysql/;./scripts/mysql_install_db --datadir=/usr/local/mysql/data3306/ --user=mysql
查询是否启动: mysqld_multi --defaults-extra-file=/etc/my_muti.cnf report
启动:
mysqld_multi --defaults-extra-file=/etc/my_muti.cnf start
初始话成功,会提示OK,否则查看数据库目录是否有权限
本机登录Mysql,如3307端口:
- shell>mysql -S /tmp/mysql3307.sock
-
- mysql> show variables like 'datadir';
-
- +---------------+----------------------+
-
- | Variable_name | Value |
-
- +---------------+----------------------+
-
- | datadir | /mysqldata/data3307/ |
-
- +---------------+----------------------+
-
- 1 row in set (0.00 sec)
4、关闭数据库实例
- shell>/usr/local/mysql/bin/mysqld_multi stop 1-2
-
- 或
-
- shell>/usr/local/mysql/bin/mysqld_multi stop 1
-
- shell>/usr/local/mysql/bin/mysqld_multi stop 2