1. Installmysql
(1) Unzipmysqlpackage and createmysqlUsers and creationmysqldata directory span>
tar zxvf mysql-5.6.43-linux -glibc2.12-x86_64.tar.gz mv mysql-5.6.43-linux-glibc2.12-x86_64 /usr/local/mysql useradd -s /sbin/ nologin mysql mkdir -p /data/mysql |
(2)< span style="font-family: 宋体;">copy the source code package mysqlstartup file and configuration file
cd /usr/local/mysql yum _-y install autoconf ./scripts/mysql_install_db –user=mysql –datadir=/data/mysql cp support-files/m ysql.server /etc/init.d/mysqld cp support-files/my-default.cnf /etc/my.cnf (Prompt whether to overwrite, fill iny)cp: overwrite’/etc/my.cnf’? y chmod 755 /etc/init.d/mysqld chkconfig –add mysqld chkconfig mysqld on |
(3) EditmysqlThe startup file
vi /etc/init.d/mysqld |
Modify the parameters as follows:
basedir=/usr/local/mysql datadir=/data/mysql ###Save and exit. |
(4) Startmysql< /p>
/etc/init.d/mysqld start netstat -lntp |grep mysql |
The execution effect, such as Figure2shown
Instructionsmysql Master start completed
(5) copy mastermysqlAs a slave, the example is as follows.
cp -r /usr/local /mysql /usr/local/mysql2 cd /usr/local/mysql2 mkdir -p /data/mysql2 cp /etc/init.d /mysqld /etc/init.d/mysqld2 ./scripts/mysql_install_db –user=mysql –datadir=/data/mysql2 |
(6) Configuration frommysqland start.
chmod 755 /etc/init. d/mysqld2 chkconfig –add mysqld2 chkconfig mysqld2 on vi /etc/init.d/mysqld2 ## #Add the following parameters basedir= /usr/local/mysql2 datadir=/data/mysql2< /p> ###Save and exit vi my.cnf #### Add the following parameters port =3307 ####Save and exit /etc/init.d/mysqld2 start netstat -lntp |grep mysql |
The execution effect is shown in the figure3shown.
(7) Next, configure the main database
The front is mainly to build the main database and the slave database, you can see3306and3307port, which means that both master and slave databases Get up, now configure the replication of master and slave below,First configure/etc/my.cnf(Main configuration file)
vi /etc/my.cnf ###Add the following Content server_id = 1 log_bin = master ###Save and exit /etc/init.d/mysqld restart ####Copy the mysqldata of the main database as test data, and give it to the slave Library and synchronize to use. /usr/local/mysql/bin/mysqldump -uroot mysql> /tmp/mysql.sql /usr/local/mysql/bin/mysql -uroot -e “create database testsql” /usr/local/mysql/bin/mysql -uroot testsql /usr /local/mysql/bin/mysql mysql >grant replication slave on *.* to’repl’@127.0.0.1 identified by ‘123456’; mysql>flush tables with read lock; mysql >show master status; #####This is a comment ctrl+d means exit |
in the picture above file andposition will configure the slave database later use.
(8) The following configuration is from the database
vi /usr/local/mysql2/my.cnf ### Add the following content server_id = 2 ### Save and exit /etc/init.d/mysqld2 restart ####Restore the backed-up database to the slave data. The purpose here is to be consistent with the initial state of the master-slave database data. /usr/local/mysql2/bin/mysql -e “create database testsql” /usr/local/mysql2/bin/mysql testsql /usr/local/mysql2/bin/mysql mysql>stop slave; mysql>change master to master_host=’127.0.0.1′,master_user=’repl’,master_port=3306,master_password=’123456′,master_log_file=’master.000001′,master_log_pos=646075; mysql>start slave;< /p> mysql>show slave status\G; |