MySQL source code installation + master-slave replication

Source mysql5.6
upload mysql installation package to the server (virtual machine)

1. Install dependencies and compilation tools

yum -y install gcc gcc-c++ cmake ncurses-devel autoconf

2. Unzip the MySQL source code installation package

tar zxf mysql-5.6.10.tar.gz
cd mysql-5.6.10

3. Detection and configuration

cmake .

4. Compile

make

5. Installation

make install

6. Configuration

cd /usr/local/mysql/support-files/

6.1 Prepare configuration file

cp my-default.cnf /etc/my.cnf

6.2 Prepare to start the mysql script

cp mysql.server /etc/init.d/mysqld

6.3 Initialize mysql

 useradd mysql
 chown -R mysql.mysql /usr/local/mysql
 cd /usr/local/mysql/scripts
 ./mysql_install_db --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql

6.4 Make a soft connection to the mysql command

ln -s /usr/local/mysql/bin/* /usr/local/sbin/

6.5 Copy the startup file to /etc/init.d/mysql

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

7. Start mysql

service mysqld start

8. Change the configuration file, enable binary log, add the following configuration under [mysqld]

vim /etc/my.cnf

Insert picture description here

9. To slave authorized users (main operation)

mysql> reset master;  
mysql> grant replication slave on *.* to 'tom'@'192.168.59.%' identified by '123';
mysql> flush privileges;

10. View the binary log (main operation)

show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |      331 |              |                  |
+------------------+----------+--------------+------------------+

11. Log in to mysql, perform synchronization master operation

停止slave,停止同步,开始修改信息
stop slave;
写master的信息
change master to
-> master_host='192.168.189.161',      \\master的ip地址
-> master_user='tom',                   \\登录master使用的用户
-> master_password='123',                \\登录master使用密码
-> master_log_file='mysql-bin.000001',   \\master当前写入的二进制日志文件
-> master_log_pos=331;                    \\当前二进制日志最新的位置

 开启从,开始同步
start slave;

12. Check the status of the slave, and start synchronization successfully when checking

show slave status \G;

Insert picture description here

Guess you like

Origin blog.csdn.net/APPLEaaq/article/details/108931885