MySQL multi-instance explanation

Source: Internet
Author: User

Mysql has multiple instances. The datadir, pid, port, and socket of each instance should be different.

I. Foundation, very important

Each instance should configure the my. cnf file under its own datadir.
First, let's talk about the search sequence of configuration files.
First, read/etc/my. cnf
In the second search, $ datadir/my. cnf searches for this configuration file in the data directory. Each instance should configure the my. cnf file under its own datadir.
Third, defaultfile =/path/my. cnf is usually written on the command line, and mysqld_safe defaultfile =/tmp/my. cnf & is executed.
Fourth search ,~ /My. cnf configuration file for the current user.


2. Configure datadir for each instance (use the default instance data in this example)

Stop the default mysql service (to prevent damage to the default instance database): service mysql

Stop

Copy datadir
[Root @ localhost lib] # cp-r mysql/var/lib/mysql_3301
[Root @ localhost lib] # cp-r mysql/var/lib/mysql_3302

Set mysql as owner
[Root @ localhost lib] # chown-R mysql. mysql mysql_3301
[Root @ localhost lib] # chown-R mysql. mysql mysql_3302

Set mysql as the owner of the files in the folder
[Root @ localhost lib] # cd mysql_3301
[Root @ localhost mysql_3301] # chown-R mysql. mysql *
[Root @ localhost mysql_3301] # cd ../mysql_3302
[Root @ localhost mysql_3302] # chown-R mysql. mysql *

Note:
The cause of the failure is that the files in the mysql_3301 and mysql_3302 folders are not authorized to be used by mysql.

User, resulting in errors
Cd mysql_3301
Chown-R mysql. mysql *
Cd ../mysql_3302
Chown-R mysql. mysql *

3. Configuration File Options:

[Root @ localhost mysql_3302] # cd/usr/local
[Root @ localhost local] # vi 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 =/var/lib/mysql_3301/hostname. pid
Datadir =/var/lib/mysql_3301/
Log =/var/lib/mysql_3301/hostname. log
User = mysql


[Mysqld2]
Socket =/tmp/mysql_3302.sock
Port = 3302
Pid-file =/var/lib/mysql_3302/hostname. pid
Datadir =/var/lib/mysql_3302/
Log =/var/lib/mysql_3302/hostname. log
User = mysql

  • 1
  • 2
  • 3
  • Next Page

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.