Debian 9 上的 Mysql 5.6:我在服务器 serverA 上有一个非常大的表,我已经使用 定义了从 serverB 上的数据库到 serverA 上的数据库的连接,create server connA ...
并且我在 serverB 上定义了一个表,该表通过 connA 连接到非常大的桌子。
当我在 serverB 上查询联合表时,如果查询在 serverA 上快速处理,它可以正常工作:
# on serverB:
mysql> select * from game_action where game_action_id=4;
+----------------+---------+---------+------------------+-------+--------+----------+---------------------+
| game_action_id | game_id | user_id | game_instance_id | type | amount | currency | created_timestamp |
+----------------+---------+---------+------------------+-------+--------+----------+---------------------+
| 4 | 1096 | 1 | 4 | WAGER | 1.00 | GBP | 2017-09-06 14:37:15 |
+----------------+---------+---------+------------------+-------+--------+----------+---------------------+
1 row in set (0.40 sec)
但是(仍在服务器B上):
mysql> select count(*) from game_action;
ERROR 2013 (HY000): Lost connection to MySQL server during query
表很大,所以处理需要很长时间并不奇怪,但我需要能够做需要很长时间的事情。过去我们遇到过由于超时而导致连接断开的问题,并且很难解决;在 my.cnf 中更改不同的超时没有帮助。
解决此特定问题的最佳做法是什么?
编辑
我觉得非常奇怪的是,似乎没有任何超时变量与我看到的相匹配——我设置了一个 mysql 实例只是为了测试它:
$ # On serverB:
$ time mysql -u root -pAtauseq01 gameiom -e "select count(*) from game_action;"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2013 (HY000) at line 1: Lost connection to MySQL server during query
real 9m23.275s
user 0m0.014s
sys 0m0.004s
所以,如果是超时,大约 9 分钟超时。但是在远程服务器(serverA)上:
mysql> show variables like "%timeout%";
+-------------------------------------+----------+
| Variable_name | Value |
+-------------------------------------+----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| have_statement_timeout | YES |
| innodb_flush_log_at_timeout | 1 |
| innodb_lock_wait_timeout | 50 |
| innodb_print_lock_wait_timeout_info | OFF |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 28800 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| rpl_stop_slave_timeout | 31536000 |
| slave_net_timeout | 3600 |
| thread_pool_idle_timeout | 60 |
| wait_timeout | 28800 |
+-------------------------------------+----------+
15 rows in set (0.00 sec)
编辑 2
服务器A:
mysql> show variables like "flush%";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| flush | OFF |
| flush_time | 0 |
+---------------+-------+
2 rows in set (0.00 sec)
服务器B:
mysql> show variables like "flush%";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| flush | OFF |
| flush_time | 0 |
+---------------+-------+
2 rows in set (0.01 sec)
编辑 3
在服务器 A 上:
mysql> pager grep -v PARTITION
PAGER set to 'grep -v PARTITION'
mysql> show create table game_action\G
*************************** 1. row ***************************
Table: game_action
Create Table: CREATE TABLE `game_action` (
`game_action_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`game_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`game_instance_id` bigint(20) unsigned DEFAULT NULL,
`type` varchar(15) NOT NULL,
`amount` decimal(18,2) NOT NULL,
`currency` varchar(15) NOT NULL,
`created_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`game_action_id`,`created_timestamp`),
KEY `GA_IX01` (`game_id`),
KEY `GA_IX02` (`user_id`),
KEY `GA_IX03` (`game_instance_id`),
KEY `game_action_created_timestamp` (`created_timestamp`),
KEY `ga_id_cur_tstmp` (`game_id`,`currency`,`created_timestamp`)
) ENGINE=InnoDB AUTO_INCREMENT=1064199804 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
在服务器 B 上:
mysql> show create table game_action\G
*************************** 1. row ***************************
Table: game_action
Create Table: CREATE TABLE `game_action` (
`game_action_id` bigint unsigned NOT NULL AUTO_INCREMENT,
`game_id` int NOT NULL,
`user_id` int NOT NULL,
`game_instance_id` bigint unsigned DEFAULT NULL,
`type` varchar(15) NOT NULL,
`amount` decimal(18,2) NOT NULL,
`currency` varchar(15) NOT NULL,
`created_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`game_action_id`,`created_timestamp`),
KEY `GA_IX01` (`game_id`),
KEY `GA_IX02` (`user_id`),
KEY `GA_IX03` (`game_instance_id`),
KEY `game_action_created_timestamp` (`created_timestamp`),
KEY `ga_id_cur_tstmp` (`game_id`,`currency`,`created_timestamp`)
) ENGINE=FEDERATED DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci CONNECTION='gameiom'
1 row in set (0.00 sec)
如果你会从 MySQL 命令提示符,SET GLOBAL NET_READ_TIMEOUT=3600; 在服务器 A 和服务器 B 上,它可能足以将所有 100 万行数据从表中推送到服务器 B。
观察,A) 两个 SHOW CREATE TABLES 在 CHARSET 和 COLLATE 策略上有一些显着差异。不确定这有多重要,但它可能很重要。
下一个 URL 是多年前 Baron Schwartz 的 FEDERATED 引擎详细文档。他记录了许多关于他在发动机可用性早期如何测试的详细细节。 https://www.xaprb.com/blog/2007/01/29/mysqls-federated-storage-engine-part-1/
和 https://www.xaprb.com/blog/2007/01/31/mysqls -联合存储引擎第 2 部分/
下一个 URL 用于从 MySQL 解决丢失连接的可能 - https://dev.mysql.com/doc/refman/5.7/en/error-lost-connection.html