首页 > 数据库 > 【MySQL 8.0】通过mysqldump与mysqlimport迁移表

【MySQL 8.0】通过mysqldump与mysqlimport迁移表

时间:2023-08-25 20:32:35浏览次数:47  
标签:customer 8.0 mysqlimport rw -- node02 mysqldump mysql files

[mysql@node01 ~]$ mysql -uroot -pabcd.1234 -hnode01 -D tpcc10 
(root@node01) > select count(*) from customer;
+----------+
| count(*) |
+----------+
|   300000 |
+----------+
1 row in set (0.06 sec)

(root@node01) > select @@global.secure_file_priv; 
+---------------------------+
| @@global.secure_file_priv |
+---------------------------+
| /var/lib/mysql-files/     |
+---------------------------+

[mysql@node01 ~]$ mysqldump -uroot -pabcd.1234 --tab=/var/lib/mysql-files --fields-terminated-by=',' --fields-enclosed-by='"' --lines-terminated-by='\n' tpcc10 customer
[mysql@node01 ~]$ ls -lh /var/lib/mysql-files/
total 175M
-rw-rw-r-- 1 mysql mysql 2.3K Apr  2 20:50 customer.sql
-rw-rw-rw- 1 mysql mysql 175M Apr  2 20:50 customer.txt

[mysql@node01 ~]$ ssh-keygen
[mysql@node01 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub mysql@node02
[mysql@node01 ~]$ ssh node02 date
Sun Apr  2 21:17:27 CST 2023

[mysql@node01 ~]$ scp /var/lib/mysql-files/* node02:/var/lib/mysql-files/
[mysql@node02 ~]$ mysql -uroot -pabcd.1234 tpcc10 < /var/lib/mysql-files/customer.sql

[mysql@node02 ~]$ mysqlimport -uroot -pabcd.1234 tpcc10 --fields-terminated-by=',' --fields-enclosed-by='"' --lines-terminated-by='\n' /var/lib/mysql-files/customer.txt
tpcc10.customer: Records: 300000  Deleted: 0  Skipped: 0  Warnings: 0

[mysql@node02 ~]$ mysql -uroot -pabcd.1234 -hnode02 -D tpcc10 
(root@node02) > select count(*) from customer;
+----------+
| count(*) |
+----------+
|   300000 |
+----------+
1 row in set (0.06 sec)
[root@node02 ~]# yum install -y parallel

[mysql@node02 ~]$cd /var/lib/mysql-files

[mysql@node02 mysql-files]$ wc -l customer.txt
300000 customer.txt

[mysql@node02 mysql-files]$ split -l 50000 customer.txt customer.

[mysql@node01 mysql-files]$ ls -ltrh customer.a*
-rw-rw-r-- 1 mysql mysql 30M Aug 10 22:40 customer.aa
-rw-rw-r-- 1 mysql mysql 30M Aug 10 22:40 customer.ab
-rw-rw-r-- 1 mysql mysql 30M Aug 10 22:40 customer.ac
-rw-rw-r-- 1 mysql mysql 30M Aug 10 22:40 customer.ad
-rw-rw-r-- 1 mysql mysql 30M Aug 10 22:40 customer.ae
-rw-rw-r-- 1 mysql mysql 30M Aug 10 22:40 customer.af

[mysql@node02 mysql-files]$ wc -l customer.aa
50000 customer.aa

[mysql@node02 ~]$ vim load.sh 
#!/bin/sh
find /var/lib/mysql-files -name 'customer.a*' > /tmp/data.txt
while read -r line
do
   echo mysqlimport -uroot -pabcd.1234 tpcc10 --fields-terminated-by="','" --fields-enclosed-by=\'\"\' --lines-terminated-by="'\n'" $line >>load.txt
done < /tmp/data.txt

[mysql@node02 ~]# chmod a+x load.sh
[mysql@node02 ~]# ./load.sh 

[mysql@node02 ~]$ time parallel -j 6 :::: load.txt  
......
tpcc10.customer: Records: 50000  Deleted: 0  Skipped: 0  Warnings: 0
mysqlimport: [Warning] Using a password on the command line interface can be insecure.
tpcc10.customer: Records: 50000  Deleted: 0  Skipped: 0  Warnings: 0
mysqlimport: [Warning] Using a password on the command line interface can be insecure.
tpcc10.customer: Records: 50000  Deleted: 0  Skipped: 0  Warnings: 0
mysqlimport: [Warning] Using a password on the command line interface can be insecure.
tpcc10.customer: Records: 50000  Deleted: 0  Skipped: 0  Warnings: 0
mysqlimport: [Warning] Using a password on the command line interface can be insecure.
tpcc10.customer: Records: 50000  Deleted: 0  Skipped: 0  Warnings: 0
mysqlimport: [Warning] Using a password on the command line interface can be insecure.
tpcc10.customer: Records: 50000  Deleted: 0  Skipped: 0  Warnings: 0
mysqlimport: [Warning] Using a password on the command line interface can be insecure.

标签:customer,8.0,mysqlimport,rw,--,node02,mysqldump,mysql,files
From: https://blog.51cto.com/dbprofessional/7235069

相关文章

  • 【MySQL 8.0】在线开启与关闭GTID复制
    在线开启GTID复制(root@node01)>setglobalenforce_gtid_consistency=warn;QueryOK,0rowsaffected(0.04sec)(root@node02)>setglobalenforce_gtid_consistency=warn;QueryOK,0rowsaffected(0.07sec)(root@node01)>setglobalenf......
  • 【MySQL 8.0】--通过组复制实现primary的switchover与failover
    [mysql@node01~]#uuidgen8d1945a5-5c74-4ba0-8240-e9d731110753[mysql@node01~]$vim/etc/my.cnfserver_id=101log_bin=mysql-binbinlog_cache_size=16Mmax_binlog_size=128M......
  • 【MySQL 8.0】通过Clone Plugin实现数据库的复制
    (root@node01)>createuser'donor'@'%'identifiedby'donor';QueryOK,0rowsaffected(0.10sec)(root@node01)>grantbackup_adminon*.*to'donor'@'%';QueryOK,0rowsaffected(0.23sec)(r......
  • 【MySQL 8.0】通过mysqlpump实现数据库对象的逻辑备份与恢复
    转储数据库mysqlpump-uroot-p--all-databases>full.sqlmysqlpump-uroot-p--all-databases--exclude-databases=soe>full.sqlmysqlpump-uroot-p--databasestpcc10>tpcc10.sqlmysqlpump-uroot-p--parallel-schemas=4:tpcc10>tpcc10.sql......
  • 【MySQL 8.0】通过mysqlbinlog实现binlog文件的远程同步
    mysqlbinlog会伪装成一个slave,连接master请求指定的binlogfile,master接收到这个请求之后创建一个binlogdump线程推送binlog给伪装的slave。[mysql@node01~]$mysql-uroot-pabcd.1234-hnode01(root@node01)>createuserrepl@'%'identifiedby'repl';QueryOK,0ro......
  • 【MySQL 8.0】部分备份与恢复验证
    [mysql@node01~]$xtrabackup--user=xtrabackup--password=xtrabackup--databases="tpcc10"--backup--target-dir=/home/mysql/backup/partial[mysql@node01~]$scp-rbackup/partial/*node02:/home/mysql/backup/partial[mysql@node01~]$mysqldump......
  • 【MySQL 8.0】物理备份与恢复验证
    [root@node01~]#wgethttps://repo.percona.com/yum/percona-release-latest.noarch.rpm[root@node01~]#rpm-ivhpercona-release-latest.noarch.rpm[root@node01~]#yuminstall-ypercona-xtrabackup-80用户与权限(root@node01)>createuserxtrabackup@'......
  • 【MySQL 8.0】增量备份与恢复验证
    [mysql@node01~]$xtrabackup--user=xtrabackup--password=xtrabackup--backup--target-dir=/home/mysql/backup/base[mysql@node01~]$./tpcc-mysql/tpcc_start-h192.168.1.101-P3306-dtpcc10-utpcc-ptpcc-w10-c10-l120[mysql@node01~]$xtrabac......
  • 主从升级(mysql5.7.39-mysql8.0.25)
    环境:OS:Centos7当前数据库版本:5.7.39(主从目前启用了审计server_audit.so,master_auto_position=1)计划升级的数据库版本:8.0.28升级顺序:先升级从库########################从库机器上的操作######################1.从库机器上安装好新版本的mysql注意端口和socket不能与......
  • 【MySQL 8.0】在 CentOS 7.5 安装 MySQL 8.0
    [root@node01~]#cat>>/etc/hosts<<EOF192.168.1.101node01EOF[root@node01~]#useraddmysql[root@node01~]#echomysql|passwd--stdinmysqlChangingpasswordforusermysql.passwd:allauthenticationtokensupdatedsuccessfully.......