MySQL Shell dump&load

1.MySQL Shell 部署

mkdir -p /data/tools
cd /data/tools
wget https://dev.mysql.com/get/Downloads/MySQL-Shell/mysql-shell-8.0.31-linux-glibc2.12-x86-64bit.tar.gz
tar xvf mysql-shell-8.0.31-linux-glibc2.12-x86-64bit.tar.gz 
ln -s /data/tools/mysql-shell-8.0.31-linux-glibc2.12-x86-64bit/bin/mysqlsh /usr/bin/mysqlsh
#创建账号
mysql -u -p'' -e"create user 'shell'@'127.0.0.1' identified  by '';GRANT all privileges ON *.* TO 'shell'@'127.0.0.1';"
#mysqlsh登录
mysqlsh -ushell -h127.0.0.1 -P -p

2.dumpInstance

在这里插入图片描述

util.dumpInstance('/data/backup/full',{compression: "none"})

命令中的 /data/backup/full 是备份目录,目标必须为空,compression: “none” 指的是不压缩
备份目录文件介绍:
在这里插入图片描述

  • @.done.json:会记录备份的结束时间,备份集的大小。备份结束时生成。
  • @.json:会记录备份的一些元数据信息,包括备份时的一致性位置点信息:binlogFile ,binlogPosition 和 gtidExecuted,这些信息可用来建立复制。
  • @.sql,@.post.sql:这两个文件只有一些注释信息。不过在通过 util.loadDump 导入数据时,我们可以通过这两个文件自定义一些 SQL。其中,@.sql 是数据导入前执行,@.post.sql 是数据导入后执行。
  • sbtest.json:记录 sbtest 中已经备份的表、视图、定时器、函数和存储过程。
  • *.tsv:数据文件。我们看看数据文件的内容。
  • sbtest@sbtest1.json:记录了表相关的一些元数据信息,如列名,字段之间的分隔符(fieldsTerminatedBy)等。
  • sbtest@sbtest1.sql:sbtest.sbtest1 的建表语句。
  • sbtest.sql:建库语句。如果这个库中存在存储过程、函数、定时器,也是写到这个文件中。
  • @.users.sql:创建账号及授权语句。默认不会备份 mysql.session,mysql.session,mysql.sys 这三个内部账号。

2.1 参数选择

#排除库名
- excludeSchemas: list of strings (default: empty) - List of schemas to
        be excluded from the dump.
#包含库名
- includeSchemas: list of strings (default: empty) - List of schemas to
        be included in the dump.
#兼容性检查
- ocimds: bool (default: false) - Enable checks for compatibility with
        MySQL Database Service (MDS)
        
- events: bool (default: true) - Include events from each dumped schema.
- routines: bool (default: true) - Include functions and stored
- users: bool (default: true) - Include users, roles and grants in the
        dump file.
- triggers: bool (default: true) - Include triggers for each dumped
        table
- dryRun: bool (default: false) - Print information about what would be
        dumped, but do not dump anything.
- threads: int (default: 4) - Use N threads to dump data chunks from the
        server.
- maxRate: string (default: "0") - Limit data read throughput to maximum
        rate, measured in bytes per second per thread. Use maxRate="0" to set
        no limit.
- compression: string (default: "zstd") - Compression used when writing
        the data dump files, one of: "none", "gzip", "zstd".


2.2 使用要求

Requirements

  - MySQL Server 5.7 or newer is required.
  - Size limit for individual files uploaded to the OCI or AWS S3 bucket is
    1.2 TiB.
  - Columns with data types which are not safe to be stored in text form
    (i.e. BLOB) are converted to Base64, hence the size of such columns
    cannot exceed approximately 0.74 * max_allowed_packet bytes, as
    configured through that system variable at the target server.
  - Schema object names must use latin1 or utf8 character set.
  - Only tables which use the InnoDB storage engine are guaranteed to be
    dumped with consistent data.

Dumps cannot be created for the following schemas:

  - information_schema,
  - mysql,
  - ndbinfo,
  - performance_schema,
  - sys.

3.dumpSchemas

util.dumpSchemas(['mambettv_club_db'],'/data2/backup/schema',{threads:40,compression: "none"})

4.loadDump

util.loadDump("/data/clubdb/schema",{loadUsers: true,threads:8})
  • excludeEvents:忽略某些定时器的导入。
  • excludeRoutines:忽略某些函数和存储过程的导入。
  • excludeSchemas:忽略某些库的导入。
  • excludeTables:忽略某些表的导入。
  • excludeTriggers:忽略某些触发器的导入。
  • excludeUsers:忽略某些账号的导入。
  • includeEvents:导入指定定时器。 includeRoutines:导入指定函数和存储过程。
    • includeSchemas:导入指定库。 includeTables:导入指定表。 includeTriggers:导入指定触发器。
  • includeUsers:导入指定账号。 loadData:是否导入数据,默认为 true。 loadDdl:是否导入 DDL 语句,默认为 true。 loadUsers:是否导入账号,默认为 false。注意,即使将 loadUsers 设置为 true,也不会导入当前正在执行导入操作的用户。 ignoreExistingObjects:是否忽略已经存在的对象,默认为 off。
  • 并行导入相关 backgroundThreads:获取元数据和 DDL文件内容的线程数。备份集如果存储在本地,backgroundThreads 默认和 threads 一致。
  • threads:并发线程数,默认为 4。
  • maxBytesPerTransaction:指定单个 LOAD DATA
    操作可加载的最大字节数。默认与 bytesPerChunk 一致。这个参数可用来规避大事务。 断点续传相关
  • progressFile:在导入的过程中,会在备份目录生成一个progressFile,用于记录加载过程中的进度信息,这个进度信息可用来实现断点续传功能。默认为load-progress…progress。
  • resetProgress:如果备份目录中存在progressFile,默认会从上次完成的地方继续执行。如果要从头开始执行,需将
  • resetProgress 设置为 true。该参数默认为 off。
  • skipBinlog:是否设置 sql_log_bin=0 ,默认 false。这一点与 mysqldump、mydumper 不同,后面这两个工具默认会禁用 Binlog。
  • updateGtidSet:更新 GTID_PURGED。可设置:off(不更新,默认值), replace(替代目标实例的 GTID_PURGED), append(追加)。
  • waitDumpTimeout:util.loadDump 可导入当前正在备份的备份集。处理完所有文件后,如果备份还没有结束(具体来说,是备份集中没有生成 @.done.json),util.loadDump 会报错退出,可指定 waitDumpTimeout 等待一段时间,单位秒。

导入时,注意 max_allowed_packet 的限制。 导入之前,需将目标实例的 local_infile 设置为 ON。\sql set global local_infile=ON;

# 为了加快可以临时关闭redo log
 MySQL  127.0.0.1:3306  JS > \sql ALTER INSTANCE DISABLE INNODB REDO_LOG;
# 查看redo log是否关闭成功
 MySQL  127.0.0.1:3306  JS > \sql SHOW GLOBAL STATUS LIKE 'Innodb_redo_log_enabled';

该工具属于客户端工具,生成的文件在客户端。
导出的时候,导出路径下不能有文件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值