Chinaunix首页 | 论坛 | 博客
  • 博客访问: 468486
  • 博文数量: 57
  • 博客积分: 877
  • 博客等级: 准尉
  • 技术积分: 1275
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-24 16:16
文章分类

全部博文(57)

文章存档

2014年(2)

2013年(15)

2012年(20)

2011年(20)

我的朋友

分类: Mysql/postgreSQL

2014-05-07 11:02:23

    今天巡检的时候发现,一台从数据库复制报错:

点击(此处)折叠或打开

  1. mysql> show slave status\G
  2. *************************** 1. row ***************************
  3.                Slave_IO_State:
  4.                   Master_Host: 10.241.19.124
  5.                   Master_User: rep
  6.                   Master_Port: 3306
  7.                 Connect_Retry: 60
  8.               Master_Log_File: mysql-bin.000098
  9.           Read_Master_Log_Pos: 58200422
  10.                Relay_Log_File: mysqld-relay-bin.000005
  11.                 Relay_Log_Pos: 418698836
  12.         Relay_Master_Log_File: mysql-bin.000092
  13.              Slave_IO_Running: No
  14.             Slave_SQL_Running: No
  15.               Replicate_Do_DB: pwchain
  16.           Replicate_Ignore_DB:
  17.            Replicate_Do_Table:
  18.        Replicate_Ignore_Table:
  19.       Replicate_Wild_Do_Table:
  20.   Replicate_Wild_Ignore_Table:
  21.                    Last_Errno: 1305
  22.                    Last_Error: Error 'FUNCTION pwchain.f_sequence does not exist' on query. Default database: 'pwchain'. Query: 'INSERT INTO nb_user(adminAccountID,netbid,userType,userName,password,setupTm,updateTm) SELECT f_sequence(1300),'3301080062',1,'admin','4QrcOUm6Wau+VuBX8g+IPg==',1397460800060,1397460800060 FROM dual WHERE NOT EXISTS (SELECT * FROM nb_user WHERE netbid='3301080062' AND userName='admin') limit 1'
  23.                  Skip_Counter: 0
  24.           Exec_Master_Log_Pos: 418698691
  25.               Relay_Log_Space: 1556378144
  26.               Until_Condition: None
  27.                Until_Log_File:
  28.                 Until_Log_Pos: 0
  29.            Master_SSL_Allowed: No
  30.            Master_SSL_CA_File:
  31.            Master_SSL_CA_Path:
  32.               Master_SSL_Cert:
  33.             Master_SSL_Cipher:
  34.                Master_SSL_Key:
  35.         Seconds_Behind_Master: NULL
  36. Master_SSL_Verify_Server_Cert: No
  37.                 Last_IO_Errno: 0
  38.                 Last_IO_Error:
  39.                Last_SQL_Errno: 1305
  40.                Last_SQL_Error: Error 'FUNCTION pwchain.f_sequence does not exist' on query. Default database: 'pwchain'. Query: 'INSERT INTO nb_user(adminAccountID,netbid,userType,userName,password,setupTm,updateTm) SELECT f_sequence(1300),'3301080062',1,'admin','4QrcOUm6Wau+VuBX8g+IPg==',1397460800060,1397460800060 FROM dual WHERE NOT EXISTS (SELECT * FROM nb_user WHERE netbid='3301080062' AND userName='admin') limit 1'
  41. 1 row in set (0.00 sec)
      错误的提示是 找不到 pwchain.f_sequence  这个函数,登录从数据库

点击(此处)折叠或打开

  1. mysql> show create FUNCTION pwchain.f_sequence\G
  2. ERROR 1305 (42000): FUNCTION f_sequence1 does not exist


再登录主数据,查看

点击(此处)折叠或打开

  1. sql> show create FUNCTION pwchain.f_sequence\G
  2. *************************** 1. row ***************************
  3.             Function: f_sequence
  4.             sql_mode: STRICT_TRANS_TABLES
  5.      Create Function: CREATE DEFINER=`root`@`localhost` FUNCTION `f_sequence`(itype int) RETURNS int(11)
  6. begin declare oid int; update sequence set id = id + 1 where idtype = itype; select id into oid from sequence where idtype = itype; return oid; end
  7. character_set_client: utf8
  8. collation_connection: utf8_general_ci
  9.   Database Collation: utf8_general_ci
  10. 1 row in set (0.00 sec)


此时,其实已经有了解决的方法,就是在从库上手动创建一个 pwchain.f_sequence 这个函数就可以。

但为什么 pwchain.f_sequence
 这个函数在从库上没有被创建呢?

查阅的相关资料,发现函数及存储过程的定义都是放在 information_shcema 库的routines 这种表中的。
主库:

点击(此处)折叠或打开

  1. mysql> select * from information_schema.ROUTINES\G
  2. *************************** 1. row ***************************
  3.        SPECIFIC_NAME: f_sequence
  4.      ROUTINE_CATALOG: NULL
  5.       ROUTINE_SCHEMA: pwchain
  6.         ROUTINE_NAME: f_sequence
  7.         ROUTINE_TYPE: FUNCTION
  8.       DTD_IDENTIFIER: int(11)
  9.         ROUTINE_BODY: SQL
  10.   ROUTINE_DEFINITION: begin declare oid int; update sequence set id = id + 1 where idtype = itype; select id into oid from sequence where idtype = itype; return oid; end
  11.        EXTERNAL_NAME: NULL
  12.    EXTERNAL_LANGUAGE: NULL
  13.      PARAMETER_STYLE: SQL
  14.     IS_DETERMINISTIC: NO
  15.      SQL_DATA_ACCESS: CONTAINS SQL
  16.             SQL_PATH: NULL
  17.        SECURITY_TYPE: DEFINER
  18.              CREATED: 2012-05-25 00:15:27
  19.         LAST_ALTERED: 2012-05-25 00:15:27
  20.             SQL_MODE: STRICT_TRANS_TABLES
  21.      ROUTINE_COMMENT:
  22.              DEFINER: root@localhost
  23. CHARACTER_SET_CLIENT: utf8
  24. COLLATION_CONNECTION: utf8_general_ci
  25.   DATABASE_COLLATION: utf8_general_ci
  26. *************************** 2. row ***************************
  27.        SPECIFIC_NAME: p_clearscore
  28.      ROUTINE_CATALOG: NULL
  29.       ROUTINE_SCHEMA: pwchain
  30.         ROUTINE_NAME: p_clearscore
  31.         ROUTINE_TYPE: PROCEDURE
  32.       DTD_IDENTIFIER: NULL
  33.         ROUTINE_BODY: SQL
  34.   ROUTINE_DEFINITION: BEGIN
  35.                 DECLARE l_memid,b INT;
  36.                 DECLARE cur1 CURSOR FOR select id from mem_memberbaseinfo where uniqueid in(memids);
  37.                 DECLARE CONTINUE HANDLER FOR NOT FOUND SET b=1;
  38.                 SET b=0;
  39.                 OPEN cur1;
  40.                         REPEAT
  41.                                 FETCH cur1 INTO l_memid;
  42.                                         IF b<>1 THEN
  43.                                                 update mem_memberaccount set score=0,remainscore=0 where id=l_memid;
  44.                                         END IF;
  45.                                 UNTIL b=1
  46.                         END REPEAT;
  47.                 CLOSE cur1;
  48.                 update mem_curmemberinfo set score=0,remainscore=0 where uniqueid in(memids);
  49.         END
  50.        EXTERNAL_NAME: NULL
  51.    EXTERNAL_LANGUAGE: NULL
  52.      PARAMETER_STYLE: SQL
  53.     IS_DETERMINISTIC: NO
  54.      SQL_DATA_ACCESS: CONTAINS SQL
  55.             SQL_PATH: NULL
  56.        SECURITY_TYPE: DEFINER
  57.              CREATED: 2012-05-24 22:41:37
  58.         LAST_ALTERED: 2012-05-24 22:41:37
  59.             SQL_MODE:
  60.      ROUTINE_COMMENT:
  61.              DEFINER: root@localhost
  62. CHARACTER_SET_CLIENT: utf8
  63. COLLATION_CONNECTION: utf8_general_ci
  64.   DATABASE_COLLATION: utf8_general_ci

从库:

点击(此处)折叠或打开

  1. mysql>select * from information_schema.ROUTINES\G
  2. Empty set (1.34 sec)
再从库上手动创建函数

点击(此处)折叠或打开

  1. mysql> stop slave;
  2. Query OK, 0 rows affected, 1 warning (0.00 sec)

  3. mysql>
  4. mysql> delimiter $$
  5. mysql> CREATE DEFINER=`root`@`localhost` FUNCTION `f_sequence`(itype int)
  6.     -> RETURNS int(11)
  7.     -> begin
  8.     -> declare oid int;
  9.     -> update sequence set id = id + 1 where idtype = itype;
  10.     -> select id into oid from sequence where idtype = itype;
  11.     -> return oid;
  12.     -> end$$
  13. Query OK, 0 rows affected (0.01 sec)

  14. mysql> show slave status\G
  15. *************************** 1. row ***************************
  16.                Slave_IO_State: Waiting for master to send event
  17.                   Master_Host: 10.241.19.124
  18.                   Master_User: rep
  19.                   Master_Port: 3306
  20.                 Connect_Retry: 60
  21.               Master_Log_File: mysql-bin.000098
  22.           Read_Master_Log_Pos: 58913321
  23.                Relay_Log_File: mysqld-relay-bin.000005
  24.                 Relay_Log_Pos: 418746091
  25.         Relay_Master_Log_File: mysql-bin.000092
  26.              Slave_IO_Running: Yes
  27.             Slave_SQL_Running: Yes
  28.               Replicate_Do_DB: pwchain
  29.           Replicate_Ignore_DB:
  30.            Replicate_Do_Table:
  31.        Replicate_Ignore_Table:
  32.       Replicate_Wild_Do_Table:
  33.   Replicate_Wild_Ignore_Table:
  34.                    Last_Errno: 0
  35.                    Last_Error:
  36.                  Skip_Counter: 0
  37.           Exec_Master_Log_Pos: 418745946
  38.               Relay_Log_Space: 1557091344
  39.               Until_Condition: None
  40.                Until_Log_File:
  41.                 Until_Log_Pos: 0
  42.            Master_SSL_Allowed: No
  43.            Master_SSL_CA_File:
  44.            Master_SSL_CA_Path:
  45.               Master_SSL_Cert:
  46.             Master_SSL_Cipher:
  47.                Master_SSL_Key:
  48.         Seconds_Behind_Master: 1814763
  49. Master_SSL_Verify_Server_Cert: No
  50.                 Last_IO_Errno: 0
  51.                 Last_IO_Error:
  52.                Last_SQL_Errno: 0
  53.                Last_SQL_Error:
  54. 1 row in set (0.00 sec)


错误恢复!

Ps:其实造成这个报错的原因应该是在开始配置主从的时候只配置 pwchain 数据库,没对information_schema 数据库进行同步配置,导致从库找不到相应的信息

 


阅读(8584) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

月歌542014-11-24 18:21:29

谢谢楼主分享,我也遇到这个问题,但是你没从根本上解决问题啊。请教,解决根本问题的方法

vwpqmgfr2014-05-08 10:19:44

路过看看!