Home >Database >Mysql Tutorial >一台MySQL服务器启动多个端口_MySQL

一台MySQL服务器启动多个端口_MySQL

WBOY
WBOYOriginal
2016-06-01 13:32:421097browse

bitsCN.com

一台MySQL服务器启动多个端口

 

在测试Mysql多主一从服务器,即一个从服务器多端口同步不同主库。本文记录了开启不同端口的操作。

 

详细步骤:

 

1、首先要先把my.cnf配置文件复制一份,开几个端口要复制几份当然要重新命名.

 

如:

 

cp /etc/my.cnf /etc/my3306.cnf

 

cp /etc/my.cnf /etc/my3307.cnf

 

cp /etc/my.cnf /etc/my3308.cnf

 

2、修改my_1.cnf my_2.cnf my_3.cnf文件把默认的3306端口改成 3307 3308 3309.

 

如:

 

[client]

 

port = 3308

 

socket = /tmp/mysql3308.sock

 

default-character-set=UTF

 

[mysqld]

 

port = 3308

 

socket = /tmp/mysql3308.sock

 

basedir=/usr/local/mysql

 

datadir=/www/mysqldata8

3、创建数据库指定存放数据的目录

 

mkdir /www/mysqldata3306

 

mkdir /www/mysqldata3307

 

mkdir /www/mysqldata3308

 

4、初始化数据库

 

/usr/local/mysql/scripts/mysql_install_db --datadir=/www/mysqldata3306/ --user=mysql --basedir=/usr/local/mysql

 

/usr/local/mysql/scripts/mysql_install_db --datadir=/www/mysqldata3307/ --user=mysql --basedir=/usr/local/mysql

 

/usr/local/mysql/scripts/mysql_install_db --datadir=/www/mysqldata3308/ --user=mysql --basedir=/usr/local/mysql

 

5、启动mysql,要指定.cnf文件和目录启动

 

/usr/local/mysql/bin/mysqld_safe --defaults-extra-file=/etc/my3306.cnf --datadir=/www/mysqldata3306 --user=mysql &

 

/usr/local/mysql/bin/mysqld_safe --defaults-extra-file=/etc/my3307.cnf --datadir=/www/mysqldata3307 --user=mysql &

 

/usr/local/mysql/bin/mysqld_safe --defaults-extra-file=/etc/my3308.cnf --datadir=/www/mysqldata3308 --user=mysql &

 

一台MySQL服务器启动多个端口_MySQL

 

6、停止MYSQL,对应的sock文件。

 

/usr/local/mysql/bin/mysqladmin -uroot -S /tmp/mysql3308.sock shutdown

 

7、登陆mysql

 

mysql -S /tmp/mysq3308.sock -P 3308

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn