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