导入数据库 MySQL 最快的方法

Import database MySQL fastest way

我正在寻找导入数据库的最快方法。问题是我使用 mysqldump 导出数据库。我的数据库在磁盘上超过 2 GB。

mysqldump速度还是挺快的,就是导入时间比较长。有没有快速导入数据库的方法?

我们尝试实现热备份,但是MySQL没有加载。是否有选项如何进行快速导出导入?那是数据文件夹中数据库文件的简单副本?

信息服务器: OS:MS Windows 服务器 2008
MySQL 服务器:MySQL 5.5 或 MariaDB
表类型:InnoDB(如果是 MariaDB - InnoDB 插件)

希望对您有所帮助...尝试导入 CSV 文件以轻松加载数据库。

例如:

LOAD DATA LOCAL INFILE 'path/caption.csv'
INTO TABLE caption
FIELDS TERMINATED BY ','
    ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(id, name)

使用此软件:

海蒂SQL SQL 编辑器软件

是的,可以将 InnoDB 文件从一台服务器复制到另一台服务器。如果您启用了 "innodb file per table",它会容易得多。按照 manual 中的说明,您可以执行以下操作:

  1. On the source server, create a table if one does not already exist:

    mysql> use test;
    mysql> CREATE TABLE t(c1 INT) engine=InnoDB;

  2. On the destination server, create a table if one does not exist:

    mysql> use test;
    mysql> CREATE TABLE t(c1 INT) engine=InnoDB;

  3. On the destination server, discard the existing tablespace. (Before a tablespace can be imported, InnoDB must discard the tablespace that is attached to the receiving table.)

    mysql> ALTER TABLE t DISCARD TABLESPACE;

  4. On the source server, run FLUSH TABLES ... FOR EXPORT to quiesce the table and create the .cfg metadata file:

    mysql> use test;
    mysql> FLUSH TABLES t FOR EXPORT;

    The metadata (.cfg) file is created in the InnoDB data directory. Note

    FLUSH TABLES ... FOR EXPORT is available as of MySQL 5.6.6. The statement ensures that changes to the named tables have been flushed to disk so that binary table copies can be made while the server is running. When FLUSH TABLES ... FOR EXPORT is run, InnoDB produces a .cfg file in the same database directory as the table. The .cfg file contains metadata used for schema verification when importing the tablespace file.

  5. 从源服务器复制.ibd文件和.cfg元数据文件到 目标服务器。例如:

    shell> scp /path/to/datadir/test/t.{ibd,cfg} 目标服务器:/path/to/datadir/test

    Note

    The .ibd file and .cfg file must be copied before releasing the shared locks, as described in the next step.

  6. 在源服务器上,使用UNLOCK TABLES释放获取的锁 通过 FLUSH TABLES ... 出口:

    mysql> 使用测试;
    mysql> 解锁 TABLES;

  7. 在目标服务器上,导入表空间:

    mysql> 使用测试; mysql> ALTER TABLE t IMPORT TABLESPACE;

    Note

    The ALTER TABLE ... IMPORT TABLESPACE feature does not enforce foreign key constraints on imported data. If there are foreign key constraints between tables, all tables should be exported at the same (logical) point in time. In this case you would stop updating the tables, commit all transactions, acquire shared locks on the tables, and then perform the export operation.

我在导入数据时遇到了与 MySQL 相同的问题,在调整以下参数后:

  1. max_allowed_packet = 1024M
  2. innodb_buffer_pool_size = 4G

导入时间显着缩短。