mysql 主从同步

第一章        安装mysql

mysql安装包:


MySQL-server-5.6.11-1.rhel5.x86_64.rpm

MySQL-client-5.6.11-1.rhel5.x86_64.rpm

安装mysql:


[[email protected] software]# rpm  -ivh MySQL-server-5.6.11-1.rhel5.x86_64.rpm

Preparing...                 ########################################### [100%]

1:MySQL-server            ########################################### [100%]

2017-03-30 17:10:00 0 [Warning] TIMESTAMP  with implicit DEFAULT value is deprecated. Please use  --explicit_defaults_for_timestamp server option (see documentation for more  details).

2017-03-30 17:10:00 24684 [Note] InnoDB:  The InnoDB memory heap is disabled

2017-03-30 17:10:00 24684 [Note] InnoDB:  Mutexes and rw_locks use GCC atomic builtins

2017-03-30 17:10:00 24684 [Note] InnoDB:  Compressed tables use zlib 1.2.3

2017-03-30 17:10:00 24684 [Note] InnoDB:  Using Linux native AIO

2017-03-30 17:10:00 24684 [Note] InnoDB:  Using CPU crc32 instructions

2017-03-30 17:10:00 24684 [Note] InnoDB:  Initializing buffer pool, size = 128.0M

2017-03-30 17:10:00 24684 [Note] InnoDB:  Completed initialization of buffer pool

2017-03-30 17:10:00 24684 [Note] InnoDB:  The first specified data file ./ibdata1 did not exist: a new database to be  created!

2017-03-30 17:10:00 24684 [Note] InnoDB:  Setting file ./ibdata1 size to 12 MB

2017-03-30 17:10:00 24684 [Note] InnoDB:  Database physically writes the file full: wait...

2017-03-30 17:10:00 24684 [Note] InnoDB:  Setting log file ./ib_logfile101 size to 48 MB

2017-03-30 17:10:00 24684 [Note] InnoDB:  Setting log file ./ib_logfile1 size to 48 MB

2017-03-30 17:10:01 24684 [Note] InnoDB:  Renaming log file ./ib_logfile101 to ./ib_logfile0

2017-03-30 17:10:01 24684 [Warning]  InnoDB: New log files created, LSN=45781

2017-03-30 17:10:01 24684 [Note] InnoDB:  Doublewrite buffer not found: creating new

2017-03-30 17:10:01 24684 [Note] InnoDB:  Doublewrite buffer created

2017-03-30 17:10:01 24684 [Note] InnoDB:  128 rollback segment(s) are active.

2017-03-30 17:10:01 24684 [Warning]  InnoDB: Creating foreign key constraint system tables.

2017-03-30 17:10:01 24684 [Note] InnoDB:  Foreign key constraint system tables created

2017-03-30 17:10:01 24684 [Note] InnoDB:  Creating tablespace and datafile system tables.

2017-03-30 17:10:01 24684 [Note] InnoDB:  Tablespace and datafile system tables created.

2017-03-30 17:10:01 24684 [Note] InnoDB:  Waiting for purge to start

2017-03-30 17:10:01 24684 [Note] InnoDB:  5.6.11 started; log sequence number 0

A random root password has been set. You  will find it in ‘/root/.mysql_secret‘.

2017-03-30 17:10:01 24684 [Note] Binlog  end

2017-03-30 17:10:01 24684 [Note] InnoDB:  FTS optimize thread exiting.

2017-03-30 17:10:01 24684 [Note] InnoDB:  Starting shutdown...

2017-03-30 17:10:03 24684 [Note] InnoDB:  Shutdown completed; log sequence number 1625977

2017-03-30 17:10:03 0 [Warning] TIMESTAMP  with implicit DEFAULT value is deprecated. Please use  --explicit_defaults_for_timestamp server option (see documentation for more  details).

2017-03-30 17:10:03 24707 [Note] InnoDB:  The InnoDB memory heap is disabled

2017-03-30 17:10:03 24707 [Note] InnoDB:  Mutexes and rw_locks use GCC atomic builtins

2017-03-30 17:10:03 24707 [Note] InnoDB:  Compressed tables use zlib 1.2.3

2017-03-30 17:10:03 24707 [Note] InnoDB:  Using Linux native AIO

2017-03-30 17:10:03 24707 [Note] InnoDB:  Using CPU crc32 instructions

2017-03-30 17:10:03 24707 [Note] InnoDB:  Initializing buffer pool, size = 128.0M

2017-03-30 17:10:03 24707 [Note] InnoDB:  Completed initialization of buffer pool

2017-03-30 17:10:03 24707 [Note] InnoDB:  Highest supported file format is Barracuda.

2017-03-30 17:10:03 24707 [Note] InnoDB:  128 rollback segment(s) are active.

2017-03-30 17:10:03 24707 [Note] InnoDB:  Waiting for purge to start

2017-03-30 17:10:03 24707 [Note] InnoDB:  5.6.11 started; log sequence number 1625977

2017-03-30 17:10:03 24707 [Note] Binlog  end

2017-03-30 17:10:03 24707 [Note] InnoDB:  FTS optimize thread exiting.

2017-03-30 17:10:03 24707 [Note] InnoDB:  Starting shutdown...

2017-03-30 17:10:05 24707 [Note] InnoDB:  Shutdown completed; log sequence number 1625987

A RANDOM PASSWORD HAS BEEN SET FOR THE  MySQL root USER !

You will find that password in  ‘/root/.mysql_secret‘.

You must change that password on your  first connect,

no other statement but ‘SET PASSWORD‘  will be accepted.

See the manual for the semantics of the  ‘password expired‘ flag.

Also, the account for the anonymous user  has been removed.

In addition, you can run:

/usr/bin/mysql_secure_installation

which will also give you the option of  removing the test database.

This is strongly recommended for  production servers.

See the manual for more instructions.

Please report any problems with the  /usr/bin/mysqlbug script!

The latest information about MySQL is  available on the web at

http://www.mysql.com

Support MySQL by buying support/licenses  at http://shop.mysql.com

New default config file was created as  /usr/my.cnf and

will be used by default by the server  when you start it.

You may edit this file to change server  settings

[[email protected] software]#

安装mysql  client端:


[[email protected] software]# rpm -ivh  MySQL-client-5.6.11-1.rhel5.x86_64.rpm

Preparing...                 ########################################### [100%]

1:MySQL-client            ########################################### [100%]

第二章        配置mysql

拷贝配置文件到/etc目录下:


[[email protected] software]# cd  /usr/share/mysql/

[[email protected] mysql]# cp  my-default.cnf /etc/my.cnf

修改配置文件:在[mysqld]下面添加如下红色标注的配置


[[email protected] mysql]# vi  /etc/my.cnf

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

lower_case_table_names=1

event_scheduler=ON

character_set_server=utf8

init_connect=‘SET NAMES  utf8‘

max_allowed_packet=256M

max_connections=1000

保存退出

root密码重置

查看mysql状态:


[[email protected] mysql]# /etc/init.d/mysql  status

ERROR! MySQL is not running

修改配置文件:在[mysqld]下面添加如下红色标注的配置


[[email protected] mysql]# vi  /etc/my.cnf

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

lower_case_table_names=1

event_scheduler=ON

character_set_server=utf8

init_connect=‘SET  NAMES utf8‘

max_allowed_packet=256M

max_connections=1000

skip-grant-tables

启动mysql:


[[email protected] mysql]#  /etc/init.d/mysql start

Starting MySQL SUCCESS!

重置root密码


[[email protected] mysql]# mysql  -uroot -p

Enter password:     【直接回车就可以】

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.11 MySQL Community  Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or  its affiliates. All rights reserved.

Oracle is a registered trademark of  Oracle Corporation and/or its

affiliates. Other names may be trademarks  of their respective

owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘  to clear the current input statement.

mysql> use mysql;

Reading table information for completion  of table and column names

You can turn off this feature to get a  quicker startup with -A

Database changed

mysql> update user set  password=password(‘rootroot‘) where user=‘root‘;

Query OK, 4 rows affected (0.00 sec)

Rows matched: 4  Changed: 4   Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> exit

修改my.cnf,删掉skip-grant-tables,开启权限认证


[[email protected] mysql]#  /etc/init.d/mysql stop

Shutting down MySQL.. SUCCESS!

[[email protected] software]# vi  /etc/my.cnf

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

lower_case_table_names=1

event_scheduler=ON

character_set_server=utf8

init_connect=‘SET NAMES utf8‘

max_allowed_packet=256M

max_connections=1000

保存退出,启动mysql


[[email protected] mysql]# /etc/init.d/mysql  start

Starting MySQL. SUCCESS!

修改root密码:


[[email protected] mysql]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.11

Copyright (c) 2000, 2013, Oracle and/or  its affiliates. All rights reserved.

Oracle is a registered trademark of  Oracle Corporation and/or its

affiliates. Other names may be trademarks  of their respective

owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘  to clear the current input statement.

mysql> use mysql;

ERROR 1820 (HY000): You must SET PASSWORD  before executing this statement

mysql> set password=password(‘rootroot‘);     #密码可根据实际情况改变

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> exit

Bye

上述步骤主库和从库都需要操作

第三章        mysql主从同步配置

主库配置:

停止mysql


[[email protected] mysql]#  /etc/init.d/mysql stop

Shutting down MySQL.. SUCCESS!

增加主库配置:增加红色标注的配置


[[email protected] mysql]# vi  /etc/my.cnf

[mysqld]

….

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

lower_case_table_names=1

event_scheduler=ON

character_set_server=utf8

init_connect=‘SET NAMES utf8‘

max_allowed_packet=256M

max_connections=1000

log-bin=mysql-bin     #启用二进制日志

binlog_format=mixed  #指定二进制日志格式

server-id=163        #指定服务器ID(建议使用ip地址的主机位)

….

启动mysql:


[[email protected] mysql]# /etc/init.d/mysql  start

Starting MySQL SUCCESS!

创建同步账号:


[[email protected] software]# mysql  -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.11-log MySQL  Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or  its affiliates. All rights reserved.

Oracle is a registered trademark of  Oracle Corporation and/or its

affiliates. Other names may be trademarks  of their respective

owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘  to clear the current input statement.

mysql> GRANT REPLICATION SLAVE ON *.*  to ‘slave‘@‘%‘ identified by ‘password123‘;

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> show master status;

+------------------+----------+--------------+------------------+-------------------+

| File             | Position | Binlog_Do_DB |  Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+-------------------+

| mysql-bin.000001 |      398 |              |                  |                   |

+------------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)

mysql>

mysql>

mysql>

mysql>

mysql> exit

Bye

[[email protected] software]#

现在主库配置完毕,记录下File和Position的值,此时主库不要做任何更改!!!

GRANT REPLICATION SLAVE ON *.* to ‘slave‘@‘%‘identified by ‘password123‘;  命令解析:

创建一个slave的账号,密码为password123,给予该账号对所有database的replication权限,%代表任意主机都可以用该账号登录到mysql,

从库配置:

停止mysql


[[email protected] mysql]#  /etc/init.d/mysql stop

Shutting down MySQL.. SUCCESS!

增加从库配置:增加红色标注的配置:


[[email protected] mysql]# vi  /etc/my.cnf

[mysqld]

….

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

lower_case_table_names=1

event_scheduler=ON

character_set_server=utf8

init_connect=‘SET NAMES utf8‘

max_allowed_packet=256M

max_connections=1000

log-bin=mysql-bin     #启用二进制日志

binlog_format=mixed  #指定二进制日志格式

server-id=164        #指定服务器ID(建议使用ip地址的主机位)

….

启动mysql:


[[email protected] mysql]# /etc/init.d/mysql  start

Starting MySQL SUCCESS!

设置从服务器:


[[email protected] software]# mysql  -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.11-log MySQL  Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or  its affiliates. All rights reserved.

Oracle is a registered trademark of  Oracle Corporation and/or its

affiliates. Other names may be trademarks  of their respective

owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘  to clear the current input statement.

mysql> change master to  master_host=‘192.168.2.163‘,master_user=‘slave‘,master_password=‘password123‘,master_log_file=‘mysql-bin.000001‘,master_log_pos=398;

Query OK, 0 rows affected, 2 warnings  (0.03 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> start slave;                                   #启动同步

Query OK, 0 rows affected (0.01 sec)

mysql> show slave status;

+----------------------------------+---------------+-------------+-------------+---------------+------------------+---------------------+------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+----------------------------+-----------+---------------------+-----------------------------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+

| Slave_IO_State                   | Master_Host   | Master_User | Master_Port |  Connect_Retry | Master_Log_File  |  Read_Master_Log_Pos | Relay_Log_File          | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running |  Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB |  Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table |  Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter |  Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File |  Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path  | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key |  Seconds_Behind_Master | Master_SSL_Verify_Server_Cert | Last_IO_Errno |  Last_IO_Error | Last_SQL_Errno | Last_SQL_Error | Replicate_Ignore_Server_Ids  | Master_Server_Id | Master_UUID                          |  Master_Info_File           | SQL_Delay  | SQL_Remaining_Delay | Slave_SQL_Running_State                                                      | Master_Retry_Count | Master_Bind | Last_IO_Error_Timestamp |  Last_SQL_Error_Timestamp | Master_SSL_Crl | Master_SSL_Crlpath |  Retrieved_Gtid_Set | Executed_Gtid_Set | Auto_Position |

+----------------------------------+---------------+-------------+-------------+---------------+------------------+---------------------+------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+----------------------------+-----------+---------------------+-----------------------------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+

| Waiting for master to send event |  192.168.2.163 | slave       |        3306 |            60 | mysql-bin.000001 |                 398 | SALT1-relay-bin.000002  |           283 | mysql-bin.000001      | Yes              | Yes               |                 |                     |                    |                        |                         |                             |          0 |            |            0 |                 398 |             456 | None            |                |             0 | No                 |                    |                    |                 |                   |                |                     0 | No                            |             0 |               |              0 |                |                             |              163 | 0490786c-1519-11e7-a1c4-000c29623e16  | /var/lib/mysql/master.info |          0 |                NULL | Slave  has read all relay log; waiting for the slave I/O thread to update it |              86400 |             |                         |                          |                |                    |                    |                   |             0 |

+----------------------------------+---------------+-------------+-------------+---------------+------------------+---------------------+------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+----------------------------+-----------+---------------------+-----------------------------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+

1 row in set (0.00 sec)

mysql>

参数解释:MASTER_HOST  :  设置要连接的主服务器的ip地址

MASTER_USER  :  设置要连接的主服务器的用户名

MASTER_PASSWORD  :  设置要连接的主服务器的密码

MASTER_LOG_FILE :  设置要连接的主服务器的bin日志的日志名称,即主机查询到的File的值;

MASTER_LOG_POS :  设置要连接的主服务器的bin日志的记录位置,即主机查询到的Position的值,(这里注意,最后一项不需要加引号。否则配置失败)

将结果复制到notepad中:

只要这两个值为YES就说明主从配置成功。

测试:在主库创建一个db,查看备库是否同步。

主库163:


[[email protected] software]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.6.11-log MySQL  Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or  its affiliates. All rights reserved.

Oracle is a registered trademark of  Oracle Corporation and/or its

affiliates. Other names may be trademarks  of their respective

owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘  to clear the current input statement.

mysql> create database yqqdb character  set utf8;

Query OK, 1 row affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test                |

| yqqdb              |

+--------------------+

5 rows in set (0.00 sec)

mysql> show master status;

+------------------+----------+--------------+------------------+-------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB  | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+-------------------+

| mysql-bin.000001 |      593 |              |                  |                   |

+------------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)

mysql> Ctrl-C -- exit!

Aborted

[[email protected] software]#

查看从库164:


mysql> show slave status;

+----------------------------------+---------------+-------------+-------------+---------------+------------------+---------------------+------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+----------------------------+-----------+---------------------+-----------------------------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+

| Slave_IO_State                   | Master_Host   | Master_User | Master_Port |  Connect_Retry | Master_Log_File  |  Read_Master_Log_Pos | Relay_Log_File          | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running |  Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB |  Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table |  Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter |  Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File |  Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path  | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key |  Seconds_Behind_Master | Master_SSL_Verify_Server_Cert | Last_IO_Errno |  Last_IO_Error | Last_SQL_Errno | Last_SQL_Error | Replicate_Ignore_Server_Ids  | Master_Server_Id | Master_UUID                          |  Master_Info_File           | SQL_Delay  | SQL_Remaining_Delay | Slave_SQL_Running_State                                                      | Master_Retry_Count |  Master_Bind | Last_IO_Error_Timestamp | Last_SQL_Error_Timestamp |  Master_SSL_Crl | Master_SSL_Crlpath | Retrieved_Gtid_Set | Executed_Gtid_Set  | Auto_Position |

+----------------------------------+---------------+-------------+-------------+---------------+------------------+---------------------+------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+----------------------------+-----------+---------------------+-----------------------------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+

| Waiting for master to send event |  192.168.2.163 | slave       |        3306 |            60 | mysql-bin.000001 |                 593 | SALT1-relay-bin.000002  |           478 | mysql-bin.000001      | Yes              | Yes               |                 |                     |                    |                        |                         |                             |          0 |            |            0 |                 593 |             651 | None            |                |             0 | No                 |                    |                    |                 |                   |                |                     0 | No                            |             0 |               |              0 |                |                             |              163 |  0490786c-1519-11e7-a1c4-000c29623e16 | /var/lib/mysql/master.info |         0 |                NULL | Slave has read all  relay log; waiting for the slave I/O thread to update it |              86400 |             |                         |                          |                |                    |                    |                   |             0 |

+----------------------------------+---------------+-------------+-------------+---------------+------------------+---------------------+------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+----------------------------+-----------+---------------------+-----------------------------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+

1 row in set (0.00 sec)

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

| yqqdb              |

+--------------------+

5 rows in set (0.01 sec)

mysql>

从库可以看到主库创建的yqqdb,说明主从配置成功。

时间: 2024-10-24 14:39:02

mysql 主从同步的相关文章

MYSQL 主从同步故障-Error1062--解决方案

MYSQL 主从同步故障-Error1062-解决方案 公司有两台Mysql服务器之前配置了主从同步,今天用户反映数据有差异,登陆到服务器上查看Mysql主从配置,发现有错误: show slave status \G;  果然出现问题了 Slave_IO_Running: Yes Slave_SQL_Running: No 而且出现了1062错误 Last_SQL_Error: Error 'Duplicate entry '1001-164761-0' for key 'PRIMARY''

检查mysql主从同步结构中的从数据库服务器的状态-脚本shell

检查mysql主从同步结构(一主一从)中的从数据库服务器的状态          (ip授权.从服务器和IO是否正常.从mysql进程是否正常) 主mysql: 192.168.1.10 从mysql: 192.168.1.20 [[email protected] ~]# vi check_slave.sh #!/bin/bash master=192.168.1.10 i=1 service mysqld status &>/dev/null while [ true ] do echo

python自动化管理mysql主从同步

mysql 多实例 1.my.cnf 通过定义mysqldconfig类   mysqld_vars = {}  从里面获得很多配置文件相关参数写入字典 mysql.py 2.init DB 初始化数据库 3.修改权限 4.rc脚本启动 5.check 检查一下配置文件,配置文件与mysql变量同步 6.值其实一样,不让显示 7.Popen 调用 mysql -e 命令 SQL IO Seconds_Behind_Master:0    看这个阀值.大于两秒 8.mysql主从 主配置文件: b

mysql主从同步(4)-同步延迟状态考量(seconds_behind_master和pt-heartbea)

一般情况下,我们是通过"show slave status \G;"提供的Seconds_Behind_Master值来衡量mysql主从同步的延迟情况.具体说明见:mysql主从同步(4)-Slave延迟状态监控,这种方法在大多数情况下确实是可行的.但是经验告诉我,仅仅依靠Seconds_Behind_Master的值来监测主从同步数据是否延迟是绝对不可靠的!!! 曾经遇到过的一个坑:Mysql主从环境部署后,刚开始主从数据同步是没问题的,也是通过监控Seconds_Behind_M

windows下的mysql主从同步

mysql主从同步: 1.为什么要主从同步? 在Web应用系统中,数据库性能是导致系统性能瓶颈最主要的原因之一.尤其是在大规模系统中,数据库集群已经成为必备的配置之一.集群的好处主要有:查询负载.数据库复制备份等.其中Master负责写操作的负载,也就是说一切写的操作都在Master上进行,而读的操作则分摊到Slave上进行.这样一来的可以大大提高读取的效率.写操作涉及到锁的问题,不管是行锁还是表锁还是块锁,都是比较降低系统执行效率的事情.我们这样的分离是把写操作集中在一个节点上,而读操作其其他

mysql主从同步中出现的问题梳理

之前部署了Mysql主从复制环境(MySQL复制环境(主从/主主)部署总结性梳理),在mysql同步过程中会出现很多问题,导致数据同步异常.以下梳理了几种主从同步中可能存在的问题:1)slave运行过慢不能与master同步,也就是MySQL数据库主从同步延迟MySQL数据库slave服务器延迟的现象是非常普遍的,MySQL复制允许从机进行SELECT操作,但是在实际线上环境下,由于从机延迟的关系,很难将读取操作转向到从机.这就导致了有了以下一些潜规则:"实时性要求不高的读取操作可以放到slav

企业生产MySQL主从同步配置

MySQL主从同步配置 前言:测试环境 一台mysql多个实例 主机IP地址 10.0.0.52 Master   3306 Salve    3307 一.主库要开启binlog服务 1. 1修改配置文件3306/my.cnf [[email protected] ~]# egrep "log-bin|server-id" /data/3306/my.cnf   log-bin = /data/3306/mysql-bin server-id = 1 1. 2查看主库有没有开启bin

MySQL主从同步、读写分离配置步骤

现在使用的两台服务器已经安装了MySQL,全是rpm包装的,能正常使用. 为了避免不必要的麻烦,主从服务器MySQL版本尽量保持一致; 环境:192.168.0.1 (Master) 192.168.0.2 (Slave) MySQL Version:Ver 14.14 Distrib 5.1.48, for pc-linux-gnu (i686) using readline 5.1 1.登录Master服务器,修改my.cnf,添加如下内容: server-id = 1 //数据库ID号,

mysql 主从同步实验细解

mysql  主从同步实验细解 一.实验环境 实验环境 192.168.9.108 为master 192.168.9.109 为slave 数据库版本:version              5.1.73 安装方式:采用的yum 安装 源为163的源 系统版本:centos 6.5 1.查看系统版本 [[email protected] ~]# cat /etc/issue CentOS release 6.5 (Final) Kernel \r on an \m 二.实验准备 1.安装my

监控mysql主从同步状态是否异常,如果异常,则发生短信或邮寄给管理员

阶段1:开发一个守护进程脚本每30秒实现检测一次. 阶段2:如果同步出现如下错误号(1158,1159,1008,1007,1062),请跳过错误 阶段3:请使用数组技术实现上述脚本(获取主从判断及错误号部分) [[email protected] ~]# mysql -u root -proot -e "show slave status\G;" *************************** 1. row ***************************