When backing up mysql data today, I encountered the Error
Error 2013
. Let’s have a look at the reason.
The scene
-bash-4.1$ mysqldump -uroot -p1234456 tpcms > ~/mysql-backup/tpcms.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
mysqldump: Error 2013: Lost connection to MySQL server during query when dumping table `cms_basic` at row: 237
Cause analysis,
Dump volume is so large that it exceeds the set timeout
time
As you can see from executing the query below, net_read_timeout
is 30 seconds, and net_write_timeout
is 90 seconds
mysql> show global 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_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 | 60 |
| wait_timeout | 28800 |
+-----------------------------+----------+
13 rows in set (0.01 sec)
The solution
After setting timeout
up, you can dump
mysql> set global net_read_timeout = 120;
Query OK, 0 rows affected (0.00 sec)
mysql> set global net_write_timeout = 900;
Query OK, 0 rows affected (0.00 sec)
mysql> show global 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_rollback_on_timeout | OFF |
| interactive_timeout | 28800 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 120 |
| net_write_timeout | 900 |
| rpl_stop_slave_timeout | 31536000 |
| slave_net_timeout | 60 |
| wait_timeout | 28800 |
+-----------------------------+----------+
13 rows in set (0.01 sec)
div>
Read More:
- MySQL Workbench: Error Code: 2013. Lost connection to MySQL server during query solution
- MySQL: if the remote connection using navicatip fails, prompt “is not allowed to connect to this MySQL server”
- SQL exception handling – MySQL error 1005 (HY000): can’t create table ‘TMP’ (errno: 13)
- “No nodes available to run query” is reported when using Presto to connect to MySQL query“
- An error occurred when MySQL backup with mysqldump instruction in MacOS system
- [resolved] exception java.net.ConnectException : Error opening socket to server Connection timed out.
- node.js Server MySQL database connection timeout (error: connect etimeout)
- Error in exporting MySQL database from Linux mysqldump:got error :1045
- MySQL local connection Error 1130_ The solution of MySQL 1130 error report when remote connection through Navicat for MySQL
- MYSQL login error: mysqladmin: connect to server at’localhost’ failed
- MySQL – ERROR 1146 (42S02): Table ‘mysql.user’ doesn’t exist
- A convenient method to count the total number of query results in MySQL
- mysql ERROR 1050 (42S01): Table already exists
- (error when importing database): MySQL 2006-mysql server has gone away
- Global lock, table lock and row lock in MySQL
- iOS Frequent Error Domains = NSURLErrorDomain Code = -1005 “Network Connection Lost.”
- Solution to error 1045 in mysqldump
- How can Oracle query tables of other users without adding a table user name
- PHP connection to MySQL database error: call to undefined function MySQL_ connect()
- MySQL error 1451 23000 foreign key exception handling