mysql同步复制

1 安装mysql
yum install gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libgcrypt* libtool* openssl* -y
groupadd mysql
useradd mysql -g mysql
mkdir /usr/local/mysql
mkdir /usr/local/mysql/data
chown -R mysql.mysql /usr/local/mysql/data/

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/usr/local/mysql/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
-DMYSQL_USER=mysql \
-DEXTRA_CHARSETS=all \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1
make && make install

./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ &
cp ../support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
mv /etc/my.cnf /etc/my.cnf_bak
cp ../support-files/my-default.cnf  /etc/my.cnf

将以下加入my.cnf:
log-bin=mysql-bin
server-id=1
innodb_flush_log_at_trx_commit=1
sync_binlog=1
#binlog-do-db=mysql
#binlog_ignore_db=mysql
不加以上注释两行,标识复制全部数据库

重启mysql

创建slave用户:
create user 'slave'@10.0.0.3 identified by 'slave';
grant replication slave on *.* to [email protected] identified by 'slave';
flush tables with read lock; 执行以下命令锁定数据库以防止写入数据
不要关闭现在窗口,新开一个窗口:
mysqldump -uroot -p --all-databases>all.sql
mysql -uroot -p
show master status; 记住
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |      494 | mysql        |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

然后在锁定数据库表窗口解锁:
unlock tables;



从数据库:

mysql -uroot -p <all.sql
mysql> change master to
    -> master_host='10.0.0.2',
    -> master_user='slave',
    -> master_password='slave',
    -> master_port=3306,
    -> master_log_file='mysql-bin.000001',
    -> master_log_pos=494,
    -> master_connect_retry=10;
新建mysql数据库测试同步



你可能感兴趣的:(mysql,local)