I finally completed multiple mysqld configurations on a single machine. I used the mysqld_safe command to complete the configuration.
Step 1:
Install the database:
./Configure -- prefix =/usr/local/mysql-master
Make & make install
./Configure -- prefix =/usr/local/mysql-slave
Make & make install
Step 2: Copy two my_small.cnf files from the support-files folder of the source code file and put them in the/etc folder named my-master.cnf, my-slave.cnf
Step 3: Modify the mysqld section of the two configuration files. For example, my configuration file is as follows:
My-master.cnf:
Port = 3306
Socket =/tmp/mysql. sock
Skip-locking
Key_buffer = 16 K
Max_allowed_packet = 1 M
Table_cache = 4
Sort_buffer_size = 64 K
Read_buffer_size = 256 K
Read_rnd_buffer_size = 256 K
Net_buffer_length = 2 K
Thread_stack = 128 K
Pid-file =/var/run/mysqld. pid
Server-id = 1
Log-bin = mysql-bin
My-slave.cnf:
Port = 3307
Socket =/tmp/mysql2.sock
Skip-locking
Key_buffer = 16 K
Max_allowed_packet = 1 M
Table_cache = 4
Sort_buffer_size = 64 K
Read_buffer_size = 256 K
Read_rnd_buffer_size = 256 K
Net_buffer_length = 2 K
Thread_stack = 128 K
Pid-file =/var/run/mysqld/mysqld2.pid
Server-id = 2
Step 4: Execute
Sudo./mysql_install_db -- defaults-file =/etc/my-master.cnf
Sudo./mysql_install_db -- defaults-file =/etc/my-slave.cnf
Step 5: Modify the data directory permission, chown mysql: mysql-R var
Step 6: Create the pid file directory and modify the permission
Sudo mkdir/var/run/mysqld
Sudo chgrp mysql/var/run/mysqld
Sudo chmod g + w/var/run/mysqld
Finally, run the corresponding servers, such as mysql-master:
./Mysqld-safe -- defaults-file =/etc/my-master.cnf
Run the client
./Mysql -- defaults-file =/etc/my-master.cnf
Of course, we can also write the corresponding server startup statement into the script to start two servers at a time.