MySQL starts multiple instances

Source: Internet
Author: User

Many of my friends want to run multiple MySQL instances on one server.
Instance. How can this problem be solved?

First, we need to clarify several principles,
The order in which mysqld reads my. CNF:

First, read/etc/My. CNF. The configuration file does not exist for multiple instances. :-(
Search for $ datadir/My. CnF in the data directory.
Third search, defaultfile =/path/My. CNF
It is usually written on the command line. Execute mysqld_safe defaultfile =/tmp/My. CNF & and so on.
Fourth search ,~ /My. CNF
The configuration file of the current user.

A necessary condition for mysqld multi-process running is that the PID file, datadir, socket, and port are separated independently.
|
Variable_name | value |
| Datadir |/home/MySQL/|
| Variable_name | value
|
| Socket |/home/MySQL. Sock |
| Variable_name | value |
|
Pid_file |/home/MySQL. PID |
| Variable_name | value |
| Port | 1, 3306
|

Multi-instance implementation in a single version
# Pwd
/Usr/local/
# Touch
My_multi.cnf
# Cat my_multi.cnf
[Mysqld_multi]
Mysqld =
/Usr/bin/mysqld_safe
Mysqladmin =/usr/bin/mysqladmin
User = root

[Mysqld1]
Socket =/tmp/mysql_3301.sock
Port = 3301
PID-file =
/Usr/local/mysql_3301/data/mysql_3301.pid
Datadir =
/Usr/local/mysql_3301/data/
Log =
/Usr/local/mysql_3301/data/mysql_3301.log
User = MySQL

[Mysqld2]
Socket =/tmp/mysql_3302.sock
Port = 3302
PID-file =
/Usr/local/mysql_3302/data/mysql_3302.pid
Datadir =
/Usr/local/mysql_3302/data/
Log =
/Usr/local/mysql_3302/data/mysql_3302.log
User = MySQL

Start two instances of mysqld

/Usr/bin/mysqld_multi-config-file =./my_multi.cnf start 1, 2

Starting mysqld daemon with databases from
/Usr/local/mysql_3301/data/
Starting mysqld daemon with databases from
/Usr/local/mysql_3302/data/

Check whether port 3301,3302 is listened on
# Netstat-lt | grep 33
TCP 0 0
*: 3301 *: * listen
TCP 0 0 *: 3302 *: * listen

Test whether MySQL can be connected.

# Pwd
/Usr/local/
Connect to mysqld of port 3001 through/tmp/mysql_3301.sock
#
Bin/MySQL-u root-S/tmp/mysql_3301.sock-e "select
@ Version ;"
Stop mysqld on port 3001
#/Usr/bin/mysqld_multi
-Config-file =./my_multi.cnf stop 1
Stopping server from PID File
/Usr/local/mysql_3301/data/mysql_3301.pid
091010 11:56:04 mysqld
Ended
Connect again and the system will prompt an error
# Bin/MySQL-u root-S
/Tmp/mysql_3301.sock-E "select @ version ;"
Error 2002 (hy000 ):
Can't
Connect to local MySQL server through socket '/tmp/mysql_3301.sock'
(2)
Test the mysqld of port 3002 in the same steps, and the output is the same as above.
#/Usr/bin/MySQL-u
Root-S/tmp/mysql_3302.sock-e "select @ version ;"
#/Usr/bin/mysqld_multi
-Config-file =./my_multi.cnf stop 2
#/Usr/bin/MySQL-u root-S
/Tmp/mysql_3302.sock-e "select @ version ;"

Add the following two sentences:
[Nova@imdba.cn MySQL] # cp
../Mysql-5.0.67/support-files/my-large.cnf/etc/My. CNF
[Nova@imdba.cn MySQL] #
CP ../mysql-5.0.67/support-files/MySQL. Server
/Etc/rc. d/init. d/mysqld
[Nova@imdba.cn MySQL] # chkconfig-add
MySQL
[Nova@imdba.cn MySQL] # chkconfig-level MySQL 345 on
Nova@imdba.cn
MySQL] # chkconfig-list MySQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.