想要在MySQL 5.1以下的版本中动态抓取提交到MySQL中的查询日志,可以采用tcpdump的方法,大致如下:
tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | egrep -i 'SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL'
eth0指mysqld监听的网卡,330自然是指mysqld监听的端口,正则匹配模式里,可以自己添加想要抓取的SQL语句类型。
本文主要探讨 mysqldump 的几种主要工作方式,并且比较一下和 mk-parralel-dump 的一些差异,为备份方式的选择提供更多的帮助。
首先来看下 mysqldump 的几个主要参数的实际工作方式。
明明是64位系统下,有16G内存,启动mysqld时指定 innodb_buffer_pool_size 为12G,却报一下错误:
080829 14:15:14 mysqld started InnoDB: HugeTLB: Warning: Failed to allocate 12884918272 bytes. errno 22 InnoDB HugeTLB: Warning: Using conventional memory pool 080829 14:15:14 InnoDB: Error: cannot allocate 12884918272 bytes of InnoDB: memory with malloc! Total allocated memory InnoDB: by InnoDB 44607312 bytes. Operating system errno: 12 InnoDB: Check if you should increase the swap file or InnoDB: ulimits of your operating system. InnoDB: On FreeBSD check you have compiled the OS with InnoDB: a big enough maximum process size. InnoDB: Note that in most 32-bit computers the process InnoDB: memory space is limited to 2 GB or 4 GB. InnoDB: We keep retrying the allocation for 60 seconds... InnoDB: Fatal error: cannot allocate the memory for the buffer pool Warning: Failed to allocate 29360128 bytes from HugeTLB memory. errno 12 Warning: Using conventional memory pool 080829 14:16:14 [Note] /usr/local/mysql/bin/mysqld: ready for connections. Version: '5.0.45-log' socket: '/home/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL)
假设有个myisam表:tbl,为了备份方便,直接把 frm 和 MYD 文件拷贝到其他目录。在还原时,就需要重新下创建索引,只需要执行以下命令:
mysql> REPAIR TABLE `tbl` USE_FRM;
即可根据 frm 和 MYD 文件,产生一个新的 MYI 索引文件。这在索引文件较大时备份还原比较有用。
另外,mysql 5.1起开始支持 分区(partition),但是如果表的某个子分区索引坏了,用 REPAIR TABLE 却无法修复,咋办呢?
其实很简单,利用 myisamchk 工具就可以修复了,例如:
path/myisamchk -rq tbl#P#P2 - check record delete-chain
其实MySQL一直都是单进程、多线程的工作模式。只是,LinuxThreads并不是真正的线程,因此,这些进程其实还是采用系统调用 clone() 来共享同样的地址空间的。尽管采用 ps 查看的结果看起来是多进程,其实mysqld真正的工作方式还是多线程。
故障现象:
1:使用mysqldump命令dump出整个数据库:
mysqldump: Got error: 1105: File './db/data_20070901.MYD' not found (Errcode: 24) when using LOCK TABLES
2:查看/data/db下面文件没有缺少,使用mysql客户端连接desc以及select * from这个表都没有问题。而且如果使用dump命令直接dump这个表也不会出错
通过 perror 24 得知,错误信息为:
[root@localhost ~]#perror 24 OS error code 24: Too many open files
因此,修改一下 /etc/my.cnf ,设定open_files_limit 为较大值,如 4096,重启mysqld生效。
innodb表不像myisam,有个内置的计数器。
1. 可以用
select count(*) from table_name where primary_key >=0
2. 或
select count(*) from table_name where key_col >=0
3. 类似这样的来查询,通过
show table status
得到的结果不够准确,会随时变化,只是个大致的值
如果该表的列数较多,那么建议用第二种方法。
问:数据库是MyISAM的,从备份库中从把a.frm,a.MYD,a.MYI覆盖掉同名文件,但不行,咋回事涅?
答:需要再执行一次 flush tables; 才会生效,因为该数据表的文件句柄已经打开了,所以需要刷新一下。
最近评论
1 天 15 小时 前
1 天 16 小时 前
2 天 12 小时 前
2 天 12 小时 前
3 天 22 小时 前
1 周 1 天 前
1 周 1 天 前