1

I have tested alot the last couple of hours and I just can't make mysql 5.7 perform very well

Have tested with a sql dump with single insert statements

In 30 sec mysql 5.7.18 could only import 290 rows while mysql 5.6.36 could import 470 rows.. It has been tested on two identical servers.. The server with mysql 5.6 was even a production server with load

  • Intel i7 2600
  • 16GB RAM
  • Tables: InnoDB

my.cnf for mysql 5.6

[client]

# CLIENT #
port            = 3306
socket          = /var/run/mysqld/mysqld.sock

[mysqld_safe]

pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]

# GENERAL #
user            = mysql
default-storage-engine  = InnoDB
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
basedir         = /usr
tmpdir          = /tmp
lc-messages-dir     = /usr/share/mysql
explicit_defaults_for_timestamp

# MyISAM #
key-buffer-size     = 32M
myisam-recover      = FORCE,BACKUP

# SAFETY #
max-allowed-packet  = 16M
max-connect-errors  = 1000000
skip-name-resolve
sql-mode        = STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY
sysdate-is-now      = 1
innodb          = FORCE
innodb-strict-mode  = 1
symbolic-links      = 0
bind_address        = 127.0.0.1

# DATA STORAGE #
datadir         = /var/lib/mysql

# BINARY LOGGING #
log-bin         = /var/lib/mysql/mysql-bin
expire-logs-days    = 10
max_binlog_size     = 100M
sync-binlog     = 1

# CACHES AND LIMITS #
tmp-table-size      = 32M
max-heap-table-size = 32M
query-cache-type    = 0
query-cache-size    = 0
max-connections     = 100
thread-cache-size   = 50
open-files-limit    = 65535
table-definition-cache  = 4096
table-open-cache    = 4096

# INNODB #
innodb-flush-method     = O_DIRECT
innodb-log-files-in-group   = 2
innodb-log-file-size        = 256M
innodb-flush-log-at-trx-commit  = 2
innodb-file-per-table       = 1
innodb-buffer-pool-size     = 12G

# MARIADB OPTIONS #
# innodb-defragment     = 1
# thread-handling           = pool-of-threads


# LOGGING #
log-error           = /var/lib/mysql/mysql-error.log
log-queries-not-using-indexes   = 1
slow-query-log          = 1
slow-query-log-file     = /var/lib/mysql/mysql-slow.log
innodb_print_all_deadlocks  = 1

my.cnf for mysql 5.7

[mysqld]

# GENERAL #
user                           = mysql
port                           = 3306
default_storage_engine         = InnoDB
pid-file                       = /var/run/mysqld/mysqld.pid
socket                         = /var/run/mysqld/mysqld.sock

# SAFETY #
max_allowed_packet             = 16M
max_connect_errors             = 1000000
skip_name_resolve
sql_mode                       = STRICT_ALL_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO
sysdate_is_now                 = 1
symbolic_links                 = 0

# DATA STORAGE #
datadir                        = /var/lib/mysql/

# BINARY LOGGING #
server_id                      = 1
log_bin                        = /var/lib/mysql/mysql-bin
log_slave_updates
expire_logs_days               = 14
sync_binlog                    = 1
log_bin_trust_function_creators= 1
binlog_format                  = ROW

# REPLICATION #
gtid_mode                      = ON
enforce_gtid_consistency

# CACHES AND LIMITS #
tmp_table_size                 = 64M
max_heap_table_size            = 64M
query_cache_type               = 0
query_cache_size               = 0
max_connections                = 500
thread_cache_size              = 50
open_files_limit               = 65535
table_definition_cache         = 4096
table_open_cache               = 4096
wait_timeout                   = 60

# INNODB #
innodb_flush_method            = O_DIRECT
innodb_log_files_in_group      = 2
innodb_log_file_size           = 1G
innodb_log_buffer_size         = 64M
innodb_flush_log_at_trx_commit = 1
innodb_file_per_table          = 1
innodb_buffer_pool_size        = 12G
innodb_buffer_pool_instances   = 8
innodb_autoinc_lock_mode       = 2
innodb_adaptive_hash_index     = 0
innodb_doublewrite             = 0
innodb_change_buffering        = none

# LOGGING #
log_error                      = /var/lib/mysql/mysql-error.log
log_queries_not_using_indexes  = 1
slow_query_log                 = 1
slow_query_log_file            = /var/lib/mysql/mysql-slow.log
long_query_time                = 1

basedir                        = /usr
tmpdir                         = /tmp
lc_messages_dir                = /usr/share/mysql
explicit_defaults_for_timestamp

Table

CREATE TABLE `account` (
  `id` mediumint(7) unsigned NOT NULL AUTO_INCREMENT,
  `block_id` smallint(5) unsigned NOT NULL,
  `account_id_` mediumint(8) unsigned NOT NULL,
  `type` tinyint(1) unsigned NOT NULL,
  `system` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `module` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `stock` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `is_bank` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `is_monitored` tinyint(1) unsigned NOT NULL,
  `vatcode_id` smallint(5) unsigned DEFAULT NULL,
  `name` varchar(40) COLLATE utf8_danish_ci NOT NULL,
  `ref_currency_id` tinyint(3) unsigned DEFAULT NULL,
  `sum_account_id_` mediumint(8) unsigned NOT NULL,
  `is_dimension` tinyint(1) unsigned NOT NULL,
  `accountoff_id` mediumint(7) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `block_id` (`block_id`,`account_id_`),
  KEY `account_id_` (`account_id_`),
  KEY `type` (`type`),
  KEY `system` (`system`),
  KEY `module` (`module`),
  KEY `stock` (`stock`),
  KEY `is_bank` (`is_bank`),
  KEY `is_monitored` (`is_monitored`),
  KEY `vatcode_id` (`vatcode_id`),
  KEY `ref_currency_id` (`ref_currency_id`),
  KEY `sum_account_id_` (`sum_account_id_`),
  KEY `accountoff_id` (`accountoff_id`),
  CONSTRAINT `account_ibfk_1` FOREIGN KEY (`block_id`) REFERENCES `block` (`id`) ON DELETE CASCADE,
  CONSTRAINT `account_ibfk_3` FOREIGN KEY (`ref_currency_id`) REFERENCES `ref_currency` (`id`),
  CONSTRAINT `account_ibfk_8` FOREIGN KEY (`vatcode_id`) REFERENCES `vatcode` (`id`) ON DELETE SET NULL,
  CONSTRAINT `account_ibfk_9` FOREIGN KEY (`accountoff_id`) REFERENCES `account` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=487803 DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci;
  • Explain "single insert statements" -- One statement with a zillion rows? Or one row per statement? – Rick James May 25 '17 at 6:01
  • @RickJames one row per statement/query – clarkk May 25 '17 at 6:12
3

innodb_flush_log_at_trx_commit = 1 is slower but safer. This probably explains the difference.

What puzzles me is how it can be so slow as to be only 10 or 15 rows per second. I would expect 100/sec, even with HDD; much more with SSD.

Would you care to provide SHOW CREATE TABLE and a sample row?

Also, what is the ROW_FORMAT being used? Are both InnoDB?

| improve this answer | |
  • Ok thanks.. That was it :) There are also alot of indexes on the table.. Its InnoDB – clarkk May 25 '17 at 6:05
  • Have added the SHOW CREATE TABLE.. When you said there should be 100/sec.. What do you think I could change in the conf to improve perfomance even more? – clarkk May 25 '17 at 6:11
  • After setting innodb_flush_log_at_trx_commit = 2 mysql 5.7 insert ~600 rows – clarkk May 25 '17 at 6:14
  • Can you bulk your INSERTs by grouping many (all) into one transaction? – Vérace May 25 '17 at 11:01
  • Do not "index every column". Do not index "flags", such indexes won't be used. Build indexes based on SELECTs – Rick James May 25 '17 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.