1.1. 前言
在DBA的工作当中导数据可谓是要经常要做的一件事,在数据量小的时候随随便便整库更新也是无所谓的。但是单数据量达到百G那整库更新起来可谓是十分费力,而且测试库的磁盘也不好。因此,经常发生的应该是单表的迁移或拷贝。
1.2. 导数据的利器
导出数据的(工具/方法)有很多:文章源自运维生存时间-https://www.ttlsa.com/mysql/migration_tools_selected_1/
- 逻辑迁移(mysqldump、mysqldumper、mysqlpump(5.7新增))
- MySQL Utilities 中的mysqldbexport和mysqldbimport
- SELECT ... INTO OUTFILE ... FROM xxx 的方法
- 使用mysql单表迁移的方法
- 使用xtrabackup 恢复单表的方法
想必上面的工具或方法多多少少大家都有尝试过。文章源自运维生存时间-https://www.ttlsa.com/mysql/migration_tools_selected_1/
1.3. 工具/方法的选择
一般在什么样的情况下应该使用哪种工具会比较好呢?文章源自运维生存时间-https://www.ttlsa.com/mysql/migration_tools_selected_1/
有许多人可能都知道数据小就用逻辑导出呗(mysqldump),如果数据大我们就使用物理导出呗。文章源自运维生存时间-https://www.ttlsa.com/mysql/migration_tools_selected_1/
那我就想问怎么样算是数据量大,怎么样算数据量小呢?文章源自运维生存时间-https://www.ttlsa.com/mysql/migration_tools_selected_1/
有很多人会直接去查看表的行数来定,如:文章源自运维生存时间-https://www.ttlsa.com/mysql/migration_tools_selected_1/
SELECT COUNT(*) FROM xx;
还有的人会使用操作系统的命令来查看磁盘数据的大小,如:文章源自运维生存时间-https://www.ttlsa.com/mysql/migration_tools_selected_1/
ls -lh xxx.ibd
其实比较正确的方法是使用数据字典information_schema.tables文章源自运维生存时间-https://www.ttlsa.com/mysql/migration_tools_selected_1/
SELECT table_name, data_length/1024/1024 AS 'data_length(MB)', index_length/1024/1024 AS 'index_length(MB)', (data_length + index_length)/1024/1024 AS 'total(MB)' FROM information_schema.tables WHERE table_schema='test' AND table_name = 't1';
之后,我们会模拟三种在不同场景下如何选择表迁移的方法:mysqlpump、xtrabackup以及复制*.ibd的方法。文章源自运维生存时间-https://www.ttlsa.com/mysql/migration_tools_selected_1/
我们这边主要的目的是不是叫你如何使用这些工具,因为这些工具在网上能找到一大片使用的方法。我们的目的在于如何选择使用它(当然会附带完整的例子)文章源自运维生存时间-https://www.ttlsa.com/mysql/migration_tools_selected_1/
1.4. 我的环境
我使用的是Percona Server文章源自运维生存时间-https://www.ttlsa.com/mysql/migration_tools_selected_1/
[root@centos7 /]# mysql -uHH -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.7.10-3-log Percona Server (GPL), Release 3, Revision 63dafaf Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. HH@(none) 18:10>SELECT @@VERSION; +--------------+ | @@VERSION | +--------------+ | 5.7.10-3-log | +--------------+ 1 row in set (0.00 sec)
文章源自运维生存时间-https://www.ttlsa.com/mysql/migration_tools_selected_1/
昵称:HH
QQ:275258836
ttlsa群交流沟通(QQ群②:6690706 QQ群③:168085569 QQ群④:415230207(新) 微信公众号:ttlsacom)文章源自运维生存时间-https://www.ttlsa.com/mysql/migration_tools_selected_1/
感觉本文内容不错,读后有收获?文章源自运维生存时间-https://www.ttlsa.com/mysql/migration_tools_selected_1/
逛逛衣服店,鼓励作者写出更好文章。文章源自运维生存时间-https://www.ttlsa.com/mysql/migration_tools_selected_1/ 文章源自运维生存时间-https://www.ttlsa.com/mysql/migration_tools_selected_1/

评论