• TiDB数据库 mydumper与loader导入数据


    mysql导出数据最好的方法是使用tidb官方的工具mydumper

    导入tidb最好的方法是使用loader工具,大概19.4G每小时的速度。

    详细的步骤可以参考官网:https://pingcap.com/docs-cn/op-guide/migration-overview/

    自己的总结:以前将mysq导出数据的时候,是一个大的sql文件,比如这次就是从mysql中导出一个41G大的文件,这是单个的。以为这样子就能使用loader命令导入到tidb中,最后发现错了。loader命令的导入是将一个目录下的sql文件导入到数据库中,那么问题就来了,像我们之前那样只有一个大的sql文件是不能使用loader命令导入数据库的。(这里的loader是tidb官方自己研发的)最后使用了source命令导入了这个大的sql文件。

    所以说要使用loader命令导入数据,那么前提是就要用mydumper命令导出数据,这样的数据才能被loader导入进去。

    mydumper命令是将一个表导出到一个目录下面,这个表比较大的时候,mydumper就会分成以64M为大小的一个个的小文件(比如这次的41G的文件分成了600多个小文件)。

    当然使用导入导出命令也踩了一些坑

    报错:

    1、导入数据出现10084错误

    这是因为端口被占用,导致不能重新写入,使用netstat -lnp| grep 10084命令找到该端口10084的对应的进程,然后使用kill命令杀死进程即可。

     2、tidb_loader数据库下check_point表的作用

    解释:当我们导入tidb数据库数据之后,这个check_point表都会产生一行数据,用来记录导入数据的状态信息以及导入时间等。

    如果你导入一次数据之后,check_point以及记录一次了,这个时候你把导入的那个表删除了,但是没有删除check_point的导入记录,那么现在你继续重新导入之前的那个表,会发现导入失败。

    下面是讲解check_point表的作用:

    mysql> select * from haha
        -> ;
    +------+------+
    | id   | name |
    +------+------+
    |    1 | chen |
    |    2 | chao |
    |    3 | feng |
    +------+------+
    3 rows in set (0.00 sec)
    
    mysql> drop table haha;
    Query OK, 0 rows affected (0.25 sec)
    
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | INFORMATION_SCHEMA |
    | PERFORMANCE_SCHEMA |
    | mob                |
    | mysql              |
    | test               |
    | tidb_loader        |
    +--------------------+
    6 rows in set (0.00 sec)
    
    mysql> use tidb_loader;
    Database changed
    mysql> show tables;
    +-----------------------+
    | Tables_in_tidb_loader |
    +-----------------------+
    | checkpoint            |
    +-----------------------+
    1 row in set (0.00 sec)
    
    mysql> select * from checkpoint;
    +--------+---------------+-----------+----------+--------+---------+---------------------+---------------------+
    | id     | filename      | cp_schema | cp_table | offset | end_pos | create_time         | update_time         |
    +--------+---------------+-----------+----------+--------+---------+---------------------+---------------------+
    | 32c716 | test.haha.sql | test      | haha     |     98 |      98 | 2018-11-16 12:00:08 | 2018-11-16 12:00:08 |
    +--------+---------------+-----------+----------+--------+---------+---------------------+---------------------+
    1 row in set (0.00 sec)
    
    mysql> exit
    Bye
    [tidb@:vg_adn_tidbCkhsTest:54.158.254.36:172.31.30.62 /usr/local/tidb-tools]$sudo bin/loader -h 127.0.0.1 -u root -P 4000 -t 1 -d /data/haha
    2018/11/16 12:01:20 printer.go:52: [info] Welcome to loader
    2018/11/16 12:01:20 printer.go:53: [info] Release Version: v1.0.0-47-gbaf98f6
    2018/11/16 12:01:20 printer.go:54: [info] Git Commit Hash: baf98f63ae77b2d9a22e00bb3d1555452b21e4f9
    2018/11/16 12:01:20 printer.go:55: [info] Git Branch: master
    2018/11/16 12:01:20 printer.go:56: [info] UTC Build Time: 2018-11-12 01:34:40
    2018/11/16 12:01:20 printer.go:57: [info] Go Version: go version go1.11 linux/amd64
    2018/11/16 12:01:20 main.go:51: [info] config: {"log-level":"info","log-file":"","pprof-addr":":10084","pool-size":1,"dir":"/data/haha","db":{"host":"127.0.0.1","user":"root","port":4000},"checkpoint-schema":"tidb_loader","config-file":"","alternative-db":"","source-db":"","route-rules":[],"do-table":null,"do-db":null,"ignore-table":null,"ignore-db":null,"rm-checkpoint":false}
    2018/11/16 12:01:20 checkpoint.go:82: [info] [loader] load checkpoint takes 0.005710 seconds
    2018/11/16 12:01:20 loader.go:524: [info] [loader] prepare takes 0.000085 seconds
    2018/11/16 12:01:20 checkpoint.go:207: [info] calc checkpoint finished. finished tables (map[test.haha:{}])
    2018/11/16 12:01:20 loader.go:685: [info] [loader][run db schema]/data/haha/test-schema-create.sql[start]
    2018/11/16 12:01:20 db.go:112: [warning] [exec][sql][CREATE DATABASE `test` /* !40100 DEFAULT CHARACTER SET utf8 */;][error]Error 1007: Can't create database 'test'; database exists
    2018/11/16 12:01:20 loader.go:689: [info] [loader][database already exists, skip]/data/haha/test-schema-create.sql
    2018/11/16 12:01:20 loader.go:694: [info] [loader][run db schema]/data/haha/test-schema-create.sql[finished]
    2018/11/16 12:01:20 loader.go:704: [info] table (test.haha) has finished, skip.
    2018/11/16 12:01:20 loader.go:750: [info] [loader] create tables takes 0.004609 seconds
    2018/11/16 12:01:20 loader.go:757: [info] [loader] all data files have been dispatched, waiting for them finished 
    2018/11/16 12:01:20 loader.go:760: [info] [loader] all data files has been finished, takes 0.004650 seconds
    2018/11/16 12:01:20 main.go:88: [info] loader stopped and exits 
    [tidb@:vg_adn_tidbCkhsTest:54.158.254.36:172.31.30.62 /usr/local/tidb-tools]$mysql -u root -P 4000 -h 127.0.0.1
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 2564
    Server version: 5.7.10-TiDB-v2.0.8 MySQL Community Server (Apache License 2.0)
    
    Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql> use test
    Database changed
    mysql> show tables;
    Empty set (0.00 sec)
    
    mysql> 
  • 相关阅读:
    启动 Appium 自带模拟器
    Android的一些常用命令提示符(cmd)指令
    Eclipse中没有andriod问题解决方法
    selenium键盘操作
    鼠标事件
    appium运行from appium import webdriver 提示most recent call last
    appium for windows 环境搭建
    python+Eclipse+pydev环境搭建
    nmon和nmon analyser的下载和使用
    Linux下使用NMON监控、分析系统性能
  • 原文地址:https://www.cnblogs.com/FengGeBlog/p/9970957.html
Copyright © 2020-2023  润新知