MySQL工作中遇到的问题记录
1:log_slave_updates:
从库1搭建级联从库2,从库1需要开启log_slave_updates,修改/etc/my.cnf,增加一行log_slave_updates=1,重启数据库。
http://blog.itpub.net/12679300/viewspace-1319263/
2:ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL,or READS SQL DATA in its declaration and binary logging is enabled(you *might* want to use the less safe log_bin_trust_function_creators variable)
主从复制架构下,从库报1418,SQL线程停止。解决:关闭log_bin=OFF,或者从库设置set global log_bin_trust_function_creators=TRUE;
3:遇到的问题:gunzip < /tmp/test.sql.gz |mysql -uroot -proot --socket=/u02/33061/tmp/mysql.sock test,第一次导入表数据,第二次导入表的增量数据,第二次的数据覆盖掉第一次导入的数据。
当将备份test.sql.gz导入新的数据库之后,如果再通过这种方式导入同一张表的增量数据时,会覆盖掉第一次导入的数据。
实验演示:

1 在同一个MySQL数据库实例下进行验证 2 session1: 3 mysql> use mydb1; 4 Reading table information for completion of table and column names 5 You can turn off this feature to get a quicker startup with -A 6 Database changed 7 mysql> select * from test; 8 +------+--------+ 9 | id | name | 10 +------+--------+ 11 | 1 | test1 | 12 | 2 | test2 | 13 | 3 | test3 | 14 | 10 | test10 | 15 | 11 | test11 | 16 | 12 | test12 | 17 | 13 | test13 | 18 | 20 | test20 | 19 | 21 | test21 | 20 | 22 | test22 | 21 | 23 | test23 | 22 +------+--------+ 23 11 rows in set (0.00 sec) 24 新建数据库test 25 mysql> create database test; 26 session2:备份mydb1下的test表的数据 27 mysqldump -uroot -p --socket=/u02/33061/tmp/mysql.sock mydb1 test |gzip > /tmp/test.sql.gz 28 导入到新数据库test 29 gunzip < /tmp/test.sql.gz |mysql -uroot -proot --socket=/u02/33061/tmp/mysql.sock test 30 session1: 31 验证test表的数据,可见,数据库成功恢复到test库 32 mysql> use test; 33 mysql> select * from test; 34 +------+--------+ 35 | id | name | 36 +------+--------+ 37 | 1 | test1 | 38 | 2 | test2 | 39 | 3 | test3 | 40 | 10 | test10 | 41 | 11 | test11 | 42 | 12 | test12 | 43 | 13 | test13 | 44 | 20 | test20 | 45 | 21 | test21 | 46 | 22 | test22 | 47 | 23 | test23 | 48 +------+--------+ 49 11 rows in set (0.00 sec) 50 51 此时,mydb1库test表新增数据 52 mysql> use mydb1; 53 mysql> insert into test values (100,'test100'); 54 mysql> select * from test; 55 +------+--------+ 56 | id | name | 57 +------+--------+ 58 | 1 | test1 | 59 | 2 | test2 | 60 | 3 | test3 | 61 | 10 | test10 | 62 | 11 | test11 | 63 | 12 | test12 | 64 | 13 | test13 | 65 | 20 | test20 | 66 | 21 | test21 | 67 | 22 | test22 | 68 | 23 | test23 | 69 | 100 | test100| 70 +------+--------+ 71 12 rows in set (0.00 sec) 72 session2: 73 对新增数据进行备份: 74 mysqldump -uroot -p --socket=/u02/33061/tmp/mysql.sock mydb1 test --where="id>23" |gzip > /tmp/test1.sql.gz 75 76 第二次导入新数据: 77 gunzip < /tmp/test1.sql.gz |mysql -uroot -proot --socket=/u02/33061/tmp/mysql.sock test 78 79 session1: 80 mysql> use test; 81 Reading table information for completion of table and column names 82 You can turn off this feature to get a quicker startup with -A 83 84 Database changed 85 mysql> select * from test; 86 +------+---------+ 87 | id | name | 88 +------+---------+ 89 | 100 | test100 | 90 +------+---------+ 91 1 row in set (0.00 sec) 92 由此可见,覆盖掉了第一次导入的数据。
分类:
MySQL管理
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南