惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
Engineering at Meta
Engineering at Meta
The Register - Security
The Register - Security
N
Netflix TechBlog - Medium
D
Docker
Vercel News
Vercel News
云风的 BLOG
云风的 BLOG
月光博客
月光博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
D
DataBreaches.Net
IT之家
IT之家
V
V2EX
人人都是产品经理
人人都是产品经理
F
Fortinet All Blogs
J
Java Code Geeks
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
博客园 - Franky
Hugging Face - Blog
Hugging Face - Blog
有赞技术团队
有赞技术团队
aimingoo的专栏
aimingoo的专栏
MongoDB | Blog
MongoDB | Blog
P
Privacy International News Feed
F
Full Disclosure
P
Proofpoint News Feed
B
Blog RSS Feed
T
Tor Project blog
T
The Blog of Author Tim Ferriss
B
Blog
Webroot Blog
Webroot Blog
腾讯CDC
T
Troy Hunt's Blog
T
Tailwind CSS Blog
H
Heimdal Security Blog
AWS News Blog
AWS News Blog
G
Google Developers Blog
Spread Privacy
Spread Privacy
NISL@THU
NISL@THU
A
About on SuperTechFans
SecWiki News
SecWiki News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
I
InfoQ
M
MIT News - Artificial intelligence
大猫的无限游戏
大猫的无限游戏
美团技术团队
L
LangChain Blog

jobcher on 打工人日志

2023-12-21 打工人日报 2023-12-20 打工人日报 2023-12-19 打工人日报 2023-12-18 打工人日报 2023-12-17 打工人日报 2023-12-16 打工人日报 2023-12-15 打工人日报 2023-12-14 打工人日报 2023-12-13 打工人日报 2023-12-12 打工人日报 2023-12-11 打工人日报 2023-12-10 打工人日报 2023-12-09 打工人日报 2023-12-08 打工人日报 2023-12-07 打工人日报 2023-12-06 打工人日报 2023-12-05 打工人日报 2023-12-04 打工人日报 2023-12-03 打工人日报 2023-12-02 打工人日报 2023-12-01 打工人日报 2023-11-30 打工人日报 2023-11-29 打工人日报 2023-11-28 打工人日报 2023-11-27 打工人日报 2023-11-26 打工人日报 2023-11-25 打工人日报 2023-11-24 打工人日报 2023-11-23 打工人日报 2023-11-22 打工人日报 2023-11-21 打工人日报 2023-11-20 打工人日报 2023-11-19 打工人日报 2023-11-17 打工人日报 2023-11-16 打工人日报 2023-11-15 打工人日报 2023-11-14 打工人日报 2023-11-13 打工人日报 2023-11-12 打工人日报 2023-11-11 打工人日报 2023-11-10 打工人日报 2023-11-09 打工人日报 2023-11-08 打工人日报 2023-11-07 打工人日报 2023-11-06 打工人日报 2023-11-05 打工人日报 2023-11-04 打工人日报 2023-11-03 打工人日报 2023-11-02 打工人日报 2023-11-01 打工人日报 2023-10-31 打工人日报 2023-10-30 打工人日报 2023-10-29 打工人日报 2023-10-28 打工人日报 2023-10-27 打工人日报 2023-10-26 打工人日报 2023-10-25 打工人日报 2023-10-24 打工人日报 2023-10-23 打工人日报 2023-10-22 打工人日报 2023-10-21 打工人日报 2023-10-20 打工人日报 2023-10-19 打工人日报 2023-10-18 打工人日报 2023-10-17 打工人日报 2023-10-16 打工人日报 2023-10-15 打工人日报 2023-10-14 打工人日报 2023-10-13 打工人日报 2023-10-12 打工人日报 2023-10-11 打工人日报 2023-10-10 打工人日报 2023-10-09 打工人日报 2023-10-07 打工人日报 2023-10-06 打工人日报 2023-10-05 打工人日报 2023-10-04 打工人日报 2023-10-03 打工人日报 2023-10-02 打工人日报 2023-10-01 打工人日报 2023-09-30 打工人日报 2023-09-29 打工人日报 2023-09-28 打工人日报 2023-09-27 打工人日报 2023-09-26 打工人日报 2023-09-25 打工人日报 2023-09-24 打工人日报 2023-09-23 打工人日报 2023-09-22 打工人日报 2023-09-21 打工人日报 2023-09-20 打工人日报 2023-09-19 打工人日报 2023-09-18 打工人日报 2023-09-17 打工人日报 2023-09-16 打工人日报 2023-09-15 打工人日报 2023-09-14 打工人日报 2023-09-13 打工人日报 2023-09-12 打工人日报 2023-09-11 打工人日报
mysql数据库备份迁移
2021-12-24 · via jobcher on 打工人日志

mysql 数据库备份迁移

使用 mydumper 做数据备份迁移

备份数据库

  1. 安装
1# 安装 centos
2yum install https://github.com/mydumper/mydumper/releases/download/v0.11.5/mydumper-0.11.5-1.el7.x86_64.rpm
3yum install https://github.com/mydumper/mydumper/releases/download/v0.11.5/mydumper-0.11.5-1.el8.x86_64.rpm
1# 安装 ubuntu
2apt-get install libatomic1
3wget https://github.com/mydumper/mydumper/releases/download/v0.11.5/mydumper_0.11.5-1.$(lsb_release -cs)_amd64.deb
4dpkg -i mydumper_0.11.5-1.$(lsb_release -cs)_amd64.deb
  1. 备份
1nohup mydumper -h '备份数据库' \
2-u '用户名' \
3-p '密码' \
4--threads=16 \
5-B 备份数据库 \
6-v 3 \
7--outputdir=./backup --rows=100000 \
8-L mydumper-logs.log &

迁移数据库

  1. 还原数据
1nohup myloader -h '迁移数据库' \
2-u '用户名' \
3-p '密码' \
4--directory=./backup \
5-s 来源数据库 \
6-B 还原数据库 \
7-t 16 \
8-v 3 \
9-e 2>myloader-logs.log &

mydumper/myloader 参数

  1. mydumper
 1Usage:
 2  mydumper [OPTION...] multi-threaded MySQL dumping
 3
 4Help Options:
 5  -?, --help                  Show help options
 6
 7Application Options:
 8  -B, --database              需要备份的数据库,一个数据库一条命令备份,要不就是备份所有数据库,包括mysql。
 9  -T, --tables-list           需要备份的表,用逗号分隔。
10  -o, --outputdir             备份文件目录
11  -s, --statement-size        生成插入语句的字节数,默认1000000,这个参数不能太小,不然会报 Row bigger than statement_size for tools.t_serverinfo
12  -r, --rows                  试图用行块来分割表,该参数关闭--chunk-filesize
13  -F, --chunk-filesize        行块分割表的文件大小,单位是MB
14  -c, --compress              压缩输出文件
15  -e, --build-empty-files     即使表没有数据,也产生一个空文件
16  -x, --regex                 正则表达式匹配,如'db.table'
17  -i, --ignore-engines        忽略的存储引擎,用逗号分隔
18  -m, --no-schemas            不导出表结构
19  -d, --no-data               不导出表数据
20  -G, --triggers              导出触发器
21  -E, --events                导出事件
22  -R, --routines              导出存储过程
23  -k, --no-locks              不执行共享读锁 警告:这将导致不一致的备份
24  --less-locking              减到最小的锁在innodb表上.
25  -l, --long-query-guard      设置长查询时间,默认60秒,超过该时间则会报错:There are queries in PROCESSLIST running longer than 60s, aborting dump
26  -K, --kill-long-queries kill掉长时间执行的查询,备份报错:Lock wait timeout exceeded; try restarting transaction
27  -D, --daemon                启用守护进程模式
28  -I, --snapshot-interval     dump快照间隔时间,默认60s,需要在daemon模式下
29  -L, --logfile               使用日志文件,默认标准输出到终端
30  --tz-utc                    备份的时候允许备份Timestamp,这样会导致不同时区的备份还原会出问题,默认关闭,参数:--skip-tz-utc to disable.
31  --skip-tz-utc
32  --use-savepoints            使用savepoints来减少采集metadata所造成的锁时间,需要SUPER权限
33  --success-on-1146           Not increment error count and Warning instead of Critical in case of table doesn't exist
34  --lock-all-tables           锁全表,代替FLUSH TABLE WITH READ LOCK
35  -U, --updated-since         Use Update_time to dump only tables updated in the last U days
36  --trx-consistency-only      Transactional consistency only
37  -h, --host                  The host to connect to
38  -u, --user                  Username with privileges to run the dump
39  -p, --password              User password
40  -P, --port                  TCP/IP port to connect to
41  -S, --socket                UNIX domain socket file to use for connection
42  -t, --threads               备份执行的线程数,默认4个线程
43  -C, --compress-protocol     在mysql连接上使用压缩协议
44  -V, --version               Show the program version and exit
45  -v, --verbose               更多输出, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default 2
  1. myloader
 1Usage:
 2  myloader [OPTION...] multi-threaded MySQL loader
 3
 4Help Options:
 5  -?, --help                        Show help options
 6
 7Application Options:
 8  -d, --directory                   备份文件所在的目录
 9  -q, --queries-per-transaction     每个事务的query数量, 默认1000
10  -o, --overwrite-tables            如果表存在则先删除,使用该参数,需要备份时候要备份表结构,不然还原会找不到表
11  -B, --database                    指定需要还原的数据库
12  -s, --source-db                   还原的数据库
13  -e, --enable-binlog               启用二进制日志恢复数据
14  -h, --host                        The host to connect to
15  -u, --user                        Username with privileges to run the dump
16  -p, --password                    User password
17  -P, --port                        TCP/IP port to connect to
18  -S, --socket                      UNIX domain socket file to use for connection
19  -t, --threads                     使用的线程数量,默认4
20  -C, --compress-protocol           连接上使用压缩协议
21  -V, --version                     Show the program version and exit
22  -v, --verbose                     更多输出, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default 2