首页 > 数据库 >通过 MySQL Shell 8.2.0 工具进行数据复制/迁移

通过 MySQL Shell 8.2.0 工具进行数据复制/迁移

时间:2023-11-09 14:26:54浏览次数:39  
标签:SRC 8.2 Creating TGT ... Shell done MySQL

一、通过sysbench创造测试数据

1、创造测试数据

[root@hankyoon db_tools]# sysbench --mysql-user=root --mysql-password='xxxxxx' --mysql-socket=/data/mysql/3307/mysql.sock /usr/share/sysbench/oltp_common.lua --tables=10 --table_size=1000000 prepare
sysbench 1.0.17 (using system LuaJIT 2.0.4)

Creating table 'sbtest1'...
Inserting 1000000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Creating table 'sbtest2'...
Inserting 1000000 records into 'sbtest2'
Creating a secondary index on 'sbtest2'...
Creating table 'sbtest3'...
Inserting 1000000 records into 'sbtest3'
Creating a secondary index on 'sbtest3'...
Creating table 'sbtest4'...
Inserting 1000000 records into 'sbtest4'
Creating a secondary index on 'sbtest4'...
Creating table 'sbtest5'...
[mysqld]
Inserting 1000000 records into 'sbtest5'
^@Creating a secondary index on 'sbtest5'...
Creating table 'sbtest6'...
Inserting 1000000 records into 'sbtest6'
Creating a secondary index on 'sbtest6'...
Creating table 'sbtest7'...
Inserting 1000000 records into 'sbtest7'
Creating a secondary index on 'sbtest7'...
Creating table 'sbtest8'...
Inserting 1000000 records into 'sbtest8'
Creating a secondary index on 'sbtest8'...
^@Creating table 'sbtest9'...
Inserting 1000000 records into 'sbtest9'
Creating a secondary index on 'sbtest9'...
Creating table 'sbtest10'...
Inserting 1000000 records into 'sbtest10'
Creating a secondary index on 'sbtest10'...

2、测试数据大小2.4G

[root@hankyoon 3307]# du -sh sbtest
2.4G    sbtest

3、通过mysql shell连接数据库

[root@hankyoon 3307]# mysqlsh -uroot -p -S /data/mysql/3307/mysql.sock
Please provide the password for 'root@/data%2Fmysql%2F3307%2Fmysql.sock': **********
Save password for 'root@/data%2Fmysql%2F3307%2Fmysql.sock'? [Y]es/[N]o/Ne[v]er (default No): y
MySQL Shell 8.2.0

Copyright (c) 2016, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.
Creating a session to 'root@/data%2Fmysql%2F3307%2Fmysql.sock'
Fetching schema names for auto-completion... Press ^C to stop.
Your MySQL connection id is 16
Server version: 8.0.28-19 Percona Server (GPL), Release 19, Revision 31e88966cd3
No default schema selected; type \use <schema> to set one.
 MySQL  localhost  JS > 

二、数据迁移:使用MySQL Shell进行数据迁移

1、迁移实例:

MySQL  localhost  JS > util.copyInstance('[email protected]:3308')
Please provide the password for '[email protected]:3308': **********
Save password for '[email protected]:3308'? [Y]es/[N]o/Ne[v]er (default No): y
ERROR: The 'local_infile' global system variable must be set to ON in the target server, after the server is verified to be trusted.

2、参数local_infile 默认为OFF,这里需要提前将目标库参数进行设置

root@localhost:(none) 06:10:12 > set global local_infile = ON;
Query OK, 0 rows affected (0.00 sec)

3、设置为on后,自动继续迁移数据,(提示:'root'@'localhost' already exists报错)

Util.copyInstance: local_infile disabled in server (MYSQLSH 53025)
 MySQL  localhost  JS > util.copyInstance('[email protected]:3308')
Copying DDL, Data and Users from in-memory FS, source: hankyoon:3307, target: hankyoon:3308.
SRC: Acquiring global read lock
SRC: Global read lock acquired
Initializing - done
SRC: 2 out of 6 schemas will be dumped and within them 10 tables, 0 views.
SRC: 1 out of 4 users will be dumped.
Gathering information - done
SRC: All transactions have been started
SRC: Locking instance for backup
SRC: Global read lock has been released
SRC: Writing global DDL files
SRC: Writing users DDL
SRC: Running data dump using 4 threads.
NOTE: SRC: Progress information uses estimated values and may not be accurate.
TGT: Opening dump...
NOTE: TGT: Dump is still ongoing, data will be loaded as it becomes available.
TGT: Target is MySQL 8.0.28-19. Dump was produced from MySQL 8.0.28-19
TGT: Scanning metadata...
TGT: Scanning metadata - done
TGT: Checking for pre-existing objects...
ERROR: TGT: Account 'root'@'localhost' already exists
ERROR: TGT: One or more objects in the dump already exist in the destination database. You must either DROP these objects or exclude them from the load.

4、这里将目标端用户root进行排除掉,并且进行并行迁移

MySQL  localhost  JS > util.copyInstance('[email protected]:3308',{threads:4,excludeUsers:["root@localhost"]})
Copying DDL, Data and Users from in-memory FS, source: hankyoon:3307, target: hankyoon:3308.
SRC: Acquiring global read lock
SRC: Global read lock acquired
Initializing - done
SRC: 2 out of 6 schemas will be dumped and within them 10 tables, 0 views.
SRC: 0 out of 4 users will be dumped.
Gathering information - done
SRC: All transactions have been started
SRC: Locking instance for backup
SRC: Global read lock has been released
SRC: Writing global DDL files
SRC: Writing users DDL
SRC: Running data dump using 4 threads.
NOTE: SRC: Progress information uses estimated values and may not be accurate.
TGT: Opening dump...
NOTE: TGT: Dump is still ongoing, data will be loaded as it becomes available.
TGT: Target is MySQL 8.0.28-19. Dump was produced from MySQL 8.0.28-19
TGT: Scanning metadata...
TGT: Scanning metadata - done
TGT: Checking for pre-existing objects...
TGT: Executing common preamble SQL
TGT: Executing DDL...
TGT: Executing DDL - done
TGT: Executing user accounts SQL...
TGT: Executing view DDL...
TGT: Executing view DDL - done
TGT: Loading data...
TGT: Starting data load
Writing schema metadata - done
Writing DDL - done
Writing table metadata - done
SRC: Starting data dump
TGT: Recreating indexes...                                                ^@
101% (10.00M rows / ~9.86M rows), 34.47K rows/s, 8.66 MB/s
SRC: Dump duration: 00:02:39s
SRC: Total duration: 00:02:39s
SRC: Schemas dumped: 2
SRC: Tables dumped: 10
SRC: Data size: 1.94 GB
SRC: Rows written: 10000000
SRC: Bytes written: 1.94 GB
SRC: Average throughput: 12.15 MB/s
TGT: Executing common postamble SQL
100% (1.94 GB / 1.94 GB), 6.69 MB/s, 10 / 10 tables done
Recreating indexes - done
TGT: 40 chunks (10.00M rows, 1.94 GB) for 10 tables in 2 schemas were loaded in 2 min 39 sec (avg throughput 12.16 MB/s)
TGT: 0 accounts were loaded
TGT: 0 warnings were reported during the load.

---
Dump_metadata:
  Binlog_file: binlog.000004
  Binlog_position: 835009314
  Executed_GTID_set: ''

 

标签:SRC,8.2,Creating,TGT,...,Shell,done,MySQL
From: https://www.cnblogs.com/hankyoon/p/17819618.html

相关文章

  • 【Linux上机实验】新实验五 shell编程
    【前言】愿,所有相遇,都恰逢其时!愿,此刻心头,正满怀欣喜!---你好,朋友,欢迎你! ---对此篇博客中有任何问题和不懂的可以咨询QQ:27595909051.编写脚本,从键盘输入10个数,并计算这些数的和(用数组存放20个数)。1.输入visum.sh,创建一个名为"sum.sh"的文件......
  • Java数据类型和MySql数据类型对应表
    javamysql数据类型对照类型名称显示长度数据库类型JAVA类型JDBC类型索引(int)描述      VARCHARL+NVARCHARjava.lang.String12 CHARNCHARjava.lang.String1 BLOBL+NBLOBjava.lang.byte[]-4 TEXT65535VARCHARjava.lang.String-1       INTEGER4IN......
  • MySQL 学习笔记--引擎
    在缺省情况下,MySQL支持三个引擎:ISAM、MyISAM和HEAP。另外两种类型InnoDB和Berkley(BDB),也常常可以使用。ISAMISAM是一个定义明确且历经时间考验的数据表格管理方法,它在设计之时就考虑到数据库被查询的次数要远大于更新的次数。因此,ISAM执行读取操作的速度很快,而且不占用大量的内存......
  • MySQL 学习笔记--架构
    1、MySQL服务器逻辑架构图:第一层:该服务并不是MySQL所独有的,大多数基于网络的客户端/服务器的工具或者服务都有的类似的架构。比如连接处理、授权认证、安全等等。第二层:MySQL的核心服务功能,包括查询解析、分析、优化、缓存以及所有的内置函数(日期、时间、加密),所有跨存引擎的功能都......
  • mysql获取插入后ID
    1.selectmax(id)fromtablename在MySQL中,使用auto_increment类型的id字段作为表的主键。通常的做法,是通过“selectmax(id)fromtablename”的做法,但是显然这种做法需要考虑并发的情况,需要在事务中对主表以“X锁“,待获得max(id)的值以后,再解锁。 2.SELECTLAST_INSERT_ID......
  • MySQL query_cache
    在服务器级别只提供了querycache,而在存储引擎级别,MyISAM和InnoDB分别引入了keycache和bufferpool什么是querycacheMysql没有shared_pool缓存执行计划,但是提供了querycache缓存sql执行结果和文本,如果在生命周期内完全相同的sql再次运行,则连sql解析都免去了;所谓完全相同,包含......
  • Proxy下的Prepare透传,让GaussDB(for MySQL)更稳固,性能更卓越
     本文分享自华为云社区《Proxy下的Prepare透传,让GaussDB(forMySQL)更稳固,性能更卓越》,作者:GaussDB数据库。1.引言在很多业务场景下,数据库应用程序处理大量相同的SQL语句——只需更改SQL语句中的文字或变量值。例如:使用相同的SQL模板进行WHERE查询,SET 更新和VALUES 插入等操......
  • MySQL常用性能指标
    一些MySQL的常用性能指标,可以对此增加一些自定义指标到数据库的监控里,如zabbix或者prometheus,来更好的检测数据库的状态。MySQSL版本是5.7.19。因为是自己的测试环境,所以截图的一些指标很低,仅为大家展示查看参数的显示情况。mysql>selectversion();+-----------+|version()|......
  • mysql-utilities对比两个库数据一致性
    1.安装mysql-utilities首先yum源安装python,之后根据python版本下载安装mysql-connector-pythonyuminstallpythonpython--versionpython2.6.6下载地址:https://downloads.mysql.com/archives/c-python/rpm-ivhmysql-connector-python-2.1.6-1.el6.x86_64.rpmwhichpython之后......
  • MySQL 单表数据最大不要超过多少行?为什么?
    1背景作为在后端圈开车的多年老司机,是不是经常听到过,“mysql单表最好不要超过2000w”,“单表超过2000w就要考虑数据迁移了”,“你这个表数据都马上要到2000w了,难怪查询速度慢”这些名言民语就和“群里只讨论技术,不开车,开车速度不要超过120码,否则自动踢群”,只听过,没试过......