我有22GB个 Big Data 库.我以前用gzip格式的mysqldump命令进行备份.

当我提取gz文件时,它会生成16.2GB.sql个文件

当我try 在本地服务器中导入数据库时,大约需要48小时才能导入.有没有办法提高进口过程的速度?

如果我想改进硬件性能,我也会知道.

当前系统配置

 Processor: 4th Gen i5
 RAM: 8GB

#update

我的cnf如下

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port        = 3306
socket      = /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket      = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
#
# * Basic Settings
#
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address        = 127.0.0.1
#
# * Fine Tuning
#
key_buffer      = 16M
max_allowed_packet  = 512M
thread_stack        = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit   = 4M
query_cache_size        = 512M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries   = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id      = 1
#log_bin            = /var/log/mysql/mysql-bin.log
expire_logs_days    = 10
max_binlog_size         = 100M
#binlog_do_db       = include_database_name
#binlog_ignore_db   = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem



[mysqldump]
quick
quote-names
max_allowed_packet  = 512M

[mysql]
#no-auto-rehash # faster start of mysql but no tab completition

[isamchk]
key_buffer      = 512M

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/

它正在上传3天,目前已导入9.9 GB.该数据库既有MyISAM个表,也有InnoDB个表.我能做些什么来提高导入性能?

我try 过以gz格式单独导出每个表,使用mysqldump,并通过执行以下代码的PHP脚本导入每个表

$dir="./";
$files = scandir($dir, 1);
array_pop($files);
array_pop($files);
$tablecount=0;
foreach($files as $file){
    $tablecount++;
    echo $tablecount."     ";

    echo $file."\n";
    $command="gunzip < ".$file." | mysql -u root -pubuntu cms";

    echo exec($command);
}

推荐答案

为了充分理解问题的原因,有很多参数缺失.例如:

  1. MySQL版本
  2. 磁盘类型和速度
  3. 在启动MySQL服务器之前释放服务器上的内存
  4. mysqldump之前和时的iostat输出.
  5. 首先,您用来创建转储文件的参数是什么.

还有更多.

所以我试着猜测你的问题出在磁盘上,因为我有150个MySQL实例,其中一个上面有3TB的数据,通常磁盘就是问题所在

现在来看解决方案:

首先,您的MySQL没有配置为最佳性能.

你可以在Percona博客上阅读最重要的配置:

特别是判断参数:

innodb_buffer_pool_size 
innodb_flush_log_at_trx_commit
innodb_flush_method

如果你的问题是磁盘——从同一个驱动器读取文件——会让问题变得更糟.

如果你的MySQL服务器因为没有足够的可用RAM而开始交换,你的问题会变得更大.

在执行恢复过程之前和执行恢复过程时,您需要在计算机上运行诊断程序来解决这个问题.

此外,我可以建议您使用另一种技术来执行重建任务,它比mysqldump工作得更快.

这是Percona Xtrabackup-http://www.percona.com/doc/percona-xtrabackup/2.2/

您需要使用它创建备份,并从中恢复,或者直接使用流媒体选项从运行的服务器重建.

此外,从5.5开始的MySQL版本——InnoDB的性能比MyISAM更快.考虑将所有表更改为它.

Mysql相关问答推荐

SQL Store Procedure Throwing [42000][1064]您在EXECUTE stat USING声明上的SQL语法中有错误

S优化联接更新的最佳方式是什么?

我需要为用户提供MySQL视图和存储的 routine ,但不是基础表

使用JSON_CONTAINS搜索多个值的原理

仅获取我不是最后一个 comments 者的博客帖子

MySQL-带有用户定义变量的IF-THEN语句

使用不同的 where 列进行子 Select

对匹配两个或多个表的表结果进行排序

如何分解分组依据的数据?

如何从将分钟、天、月和年存储在不同列中的表中查询数据

MySQL IF() 函数根据指定条件执行代码块

MySQL 查询组按日期(12 小时间隔)

添加一个日期字段大于另一个日期字段的要求

使用 MySQL 在树中查找 Leaf

如何在不违反唯一约束的情况下交换 MySQL 中两行的值?

MySQL PHP - Select WHERE id = array()?

如何通过 mysql workbench 将数据导入 mysql 数据库?

从 MYSQL 查询中计算列的平均值

MySQL 整数与日期时间索引

MySQL使用phpmyadmin重新排列列的顺序