复制中的主/从 MySQL 错误

dom*_*dal 6 mysql replication permissions mysql-5.7

我在两个独立的数据库之间设置了一个主/从,并开始正常工作,直到从出现错误并且不同步。

这是奴隶的状态:

+---------------------------------+--------------- -+-------------+------------+---------------+---- --------------+---------------------+------------ ------------------+---------------+--------------- ---+-------------------+-------------------+--- ---------------+---------------------+------------ --------+------------------------+---------------- ---------+------------------------------------------+---------- --+-------------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------+--------------+--- ------------------+-----------------+------------- ----+----------------+---------------+------------ --------+--------------------+------------ +-----------------+-------------------+----------- -----+-----------------------+------------------------------ -+---------------+---------------+---------------- +------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -----------------------------+-------------------- ---------+------------------+--------------------- -----------------+-------------------------------- --------------------------+-----------+----------- ----------+-------------------------+------------- -------+-------------+-------------------------+-- ------------------------+----------------+-------- ------------+--------------------+---------------- ---+---------------+--------------+------- -------+--------------------+--+----------------+------------------------------ -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------+- -----------------------------+--------------------+-- -------------------------+------------ ---------------------------------------------+---- -------+---------------------+-------------------- -----+------------+-------------+--------- ----------------+----------------------------------------+------ ----------+--------------------+----- --+-----------+---------------+----------- -----------+--------------+------------+--+----------------+------------------------------ -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------+- -----------------------------+--------------------+-- -------------------------+------------ ---------------------------------------------+---- -------+---------------------+-------------------- -----+------------+-------------+--------- ----------------+----------------------------------------+------ ----------+--------------------+----- --+-----------+---------------+----------- -----------+--------------+------------+-------------------------------------------------- -------------------------+------------ ----------------+------------------+-------------- ------------------------+------------------------- ---------------------------------+-----------+---- -----------------+--------------------------+------ --------------+-------------+------------ ----+----------------------------+----------------+- --------------------+------------+--------- ----------+------------------------------+--------------+ --------------+--------------------+-------------------------------------------------- -------------------------+------------ ----------------+------------------+-------------- ------------------------+------------------------- ---------------------------------+-----------+---- -----------------+--------------------------+------ --------------+-------------+------------ ----+----------------------------+----------------+- --------------------+------------+--------- ----------+------------------------------+--------------+ --------------+--------------------+----+----------------------------+------------ -------+----------------+--------------------+---- ----------------+--------------------+------------ --+----------------------+--------------+--------- -----------+----+----------------------------+------------ -------+----------------+--------------------+---- ----------------+--------------------+------------ --+----------------------+--------------+--------- -----------+
| 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 | 直到_条件 | 直到_Log_File | 直到_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | 秒_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_延迟 | 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 | Replicate_Rewrite_DB | 频道名称 | Master_TLS_Version | Last_IO_Error | Last_SQL_Errno | Last_SQL_Error | Replicate_Ignore_Server_Ids | Master_Server_Id | Master_UUID | Master_Info_File | SQL_延迟 | 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 | Replicate_Rewrite_DB | 频道名称 | Master_TLS_Version | Last_IO_Error | Last_SQL_Errno | Last_SQL_Error | Replicate_Ignore_Server_Ids | Master_Server_Id | Master_UUID | Master_Info_File | SQL_延迟 | 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 | Replicate_Rewrite_DB | 频道名称 | Master_TLS_Version | | Replicate_Ignore_Server_Ids | Master_Server_Id | Master_UUID | Master_Info_File | SQL_延迟 | 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 | Replicate_Rewrite_DB | 频道名称 | Master_TLS_Version | | Replicate_Ignore_Server_Ids | Master_Server_Id | Master_UUID | Master_Info_File | SQL_延迟 | 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 | Replicate_Rewrite_DB | 频道名称 | Master_TLS_Version | 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 | Replicate_Rewrite_DB | 频道名称 | Master_TLS_Version | 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 | Replicate_Rewrite_DB | 频道名称 | Master_TLS_Version |
+---------------------------------+--------------- -+-------------+------------+---------------+---- --------------+---------------------+------------ ------------------+---------------+--------------- ---+-------------------+-------------------+--- ---------------+---------------------+------------ --------+------------------------+---------------- ---------+------------------------------------------+---------- --+-------------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------+--------------+--- ------------------+-----------------+------------- ----+----------------+---------------+------------ --------+--------------------+------------ +-----------------+-------------------+----------- -----+------------------------+---------------------------- --+---------------+---------------+-------------- -+------------------------------------------------ -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ------------------------------+-------------------- ----------+------------------+----- ------------------+------------------------------- ---------------------------+-----------+----------- -----------+-------------------------+------------ --------+-------------+-------------------------+- -------------------------+----------------+------- -------------+------------+-------------- ----+---------------+--------------+------ ----+--------------------+----+----------------+---------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- +-------------------------------------+--------------------+ ------------------------------+------------ ---------------------------------------------------------------+-- ---------+---------------------+----- -------+------------+------------+------- -----------+---------------------------+---- ------------+--------------------+---------------- ----+--------------------+---------------+--------- -------------+--------------+------------+----+----------------+---------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- +-------------------------------------+--------------------+ ------------------------------+------------ ---------------------------------------------------------------+-- ---------+---------------------+----- -------+--------------------+------------+------- -----------+---------------------------+---- ------------+--------------------+---------------- ----+--------------------+---------------+--------- -------------+--------------+------------+-------------------------------------------------- -----------------------------------------+--------- -------------+------------------+------------ -----------------------------+------------ -------------------------------------+-----------+ ---------------------+-------------------------+-- ------------------+--------------+----------------- --------+----------------------------------------+-------------- --+--------------------+--------------------+----- --------------+---------------+------------ ---+--------------+------------+-------------------------------------------------- -----------------------------------------+--------- -------------+------------------+------------ -----------------------------+------------ -------------------------------------+-----------+ ---------------------+-------------------------+-- ------------------+--------------+----------------- --------+----------------------------------------+-------------- --+--------------------+--------------------+----- --------------+---------------+------------ ---+--------------+------------+------------+-------------------------+----------- ---------------+----------------+---------------- ---+--------------------+--------------------+----- ----------+----------------------+--------------+- -------------------+------------+-------------------------+----------- ---------------+----------------+---------------- ---+--------------------+--------------------+----- ----------+----------------------+--------------+- -------------------+
| 等待主发送事件 | 192.168.1.133 | slave_user | 3306 | 60 | mysql-bin.000033 | 154 | iMac-de-MAVA-relay-bin.000002 | 320 | mysql-bin.000001 | 是 | 没有 | | | | | | | 第1396章 查询时出现错误“操作 CREATE USER 失败,因为 'fetchers'@'localhost''。默认数据库:''。查询:'CREATE USER 'fetchers'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*A516E88562C2C5E0D1EA9875F2910B36584C217A'' | 0 | 第1166章 5614936 | 无 | | 0 | 没有 | | | | | | 空 | 没有 | 0 | | 第1396章 查询时出现错误“操作 CREATE USER 失败,因为 'fetchers'@'localhost''。默认数据库:''。查询:'CREATE USER 'fetchers'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*A516E88562C2C5E0D1EA9875F2910B36584C217A'' | | 1 | aae7157c-8bf4-11e6-a79a-4ccc6a4f12cd | /usr/local/mysql-5.7.15-osx10.11-x86_64/data/master. 信息 | 0 | 空 | | 86400 | | | 161007 13:37:26 | | | | | 0 | | | |
+---------------------------------+--------------- -+-------------+------------+---------------+---- --------------+---------------------+------------ ------------------+---------------+--------------- ---+-------------------+-------------------+--- ---------------+---------------------+------------ --------+------------------------+---------------- ---------+------------------------------------------+---------- --+-------------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------+--------------+--- ------------------+-----------------+------------- ----+----------------+---------------+------------ --------+--------------------+------------ +-----------------+-------------------+----------- -----+------------------------+---------------------------- --+---------------+---------------+-------------- -+------------------------------------------------ -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ------------------------------+-------------------- ----------+------------------+----- ------------------+------------------------------- ---------------------------+-----------+----------- -----------+-------------------------+------------ --------+-------------+-------------------------+- -------------------------+----------------+------- -------------+------------+-------------- ----+---------------+--------------+------ ----+--------------------+----+----------------+---------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- +-------------------------------------+--------------------+ ------------------------------+------------ ---------------------------------------------------------------+-- ---------+---------------------+----- -------+------------+------------+------- -----------+---------------------------+---- ------------+--------------------+---------------- ----+--------------------+---------------+--------- -------------+--------------+------------+----+----------------+---------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- +-------------------------------------+--------------------+ ------------------------------+------------ ---------------------------------------------------------------+-- ---------+---------------------+----- -------+--------------------+------------+------- -----------+---------------------------+---- ------------+--------------------+---------------- ----+--------------------+---------------+--------- -------------+--------------+------------+-------------------------------------------------- -----------------------------------------+--------- -------------+------------------+------------ -----------------------------+------------ -------------------------------------+-----------+ ---------------------+-------------------------+-- ------------------+--------------+----------------- --------+----------------------------------------+-------------- --+--------------------+--------------------+----- --------------+---------------+------------ ---+--------------+------------+-------------------------------------------------- -----------------------------------------+--------- -------------+------------------+------------ -----------------------------+------------ -------------------------------------+-----------+ ---------------------+-------------------------+-- ------------------+--------------+----------------- --------+----------------------------------------+-------------- --+--------------------+--------------------+----- --------------+---------------+------------ ---+--------------+------------+------------+-------------------------+----------- ---------------+----------------+---------------- ---+--------------------+--------------------+----- ----------+----------------------+--------------+- -------------------+------------+-------------------------+----------- ---------------+----------------+---------------- ---+--------------------+--------------------+----- ----------+----------------------+--------------+- -------------------+
1 行(0.00 秒)

问题是我只需要同步数据库中的一些表,但似乎尝试同步所有表。

如何避免复制继续工作的错误?

mysql> 显示从属状态\G;
**************************** 1. 行 ******************** *******
                Slave_IO_State:等待主机发送事件
                    Master_Host:192.168.1.133
                    主用户:slave_user
                    主端口:3306
                Connect_Retry: 60
                Master_Log_File: mysql-bin.000034
            Read_Master_Log_Pos:68326
                Relay_Log_File: iMac-de-MAVA-relay-bin.000002
                Relay_Log_Pos:320
        Relay_Master_Log_File: mysql-bin.000001
                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: 1396
                    Last_Error: 错误 'Operation CREATE USER failed for 'fetchers'@'localhost'' 查询。默认数据库:''。查询:'CREATE USER 'fetchers'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*A516E88562C2C5E0D1EA9875F2910B36584C217A''
                    跳过计数器:0
            Exec_Master_Log_Pos:1166
                Relay_Log_Space:5812332
                直到_条件:无
                直到_日志_文件: 
                直到_Log_Pos:0
            Master_SSL_Allowed:否
            Master_SSL_CA_File: 
            Master_SSL_CA_Path: 
                Master_SSL_Cert: 
            Master_SSL_Cipher: 
                Master_SSL_Key: 
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert:否
                Last_IO_Errno: 0
                Last_IO_Error: 
                Last_SQL_Errno: 1396
                Last_SQL_Error: 错误 'Operation CREATE USER failed for 'fetchers'@'localhost'' 查询。默认数据库:''。查询:'CREATE USER 'fetchers'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*A516E88562C2C5E0D1EA9875F2910B36584C217A''
    Replicate_Ignore_Server_Ids: 
                Master_Server_Id:1
                    Master_UUID:aae7157c-8bf4-11e6-a79a-4ccc6a4f12cd
                Master_Info_File: /usr/local/mysql-5.7.15-osx10.11-x86_64/data/master.info
                    SQL_延迟:0
            SQL_Remaining_Delay: NULL
        Slave_SQL_Running_State: 
            Master_Retry_Count:86400
                    Master

Rol*_*DBA 7

您发布的奴隶状态显示

查询时出现错误“‘fetchers’@‘localhost’的操作创建用户失败”。默认数据库:''。查询:'创建用户'fetchers'@'localhost',识别为'mysql_native_password' AS '*A516E88562C2C5E0D1EA9875F2910B36584C217A''

建议#1

有些人建议运行 FLUSH PRIVILEGES。所以,就你而言,那就是

STOP SLAVE;
FLUSH PRIVILEGES;
START SLAVE;
Run Code Online (Sandbox Code Playgroud)

如果错误仍然出现在从站上,您将必须运行

STOP SLAVE;
DROP USER 'fetchers'@'localhost'
START SLAVE;
Run Code Online (Sandbox Code Playgroud)

在奴隶身上。

MySQL 5.7 可能已在 Master 上生成警告并将其传递给 Slave。MySQL 5.7 的 GRANT 操作变得更加严格。以后请尝试先创建用户,再使用ALTER USER设置密码。

建议#2

用户'fetchers'@'localhost'必须已经存在于 Slave 上

如果 MySQL 5.7 在主从上,您应该运行

CREATE USER IF NOT EXISTS 'fetchers'@'localhost'
Run Code Online (Sandbox Code Playgroud)

如果已经存在,则不会执行任何操作'fetchers'@'localhost'

复制将从那里开始。