Troubleshooting of MySQL errors: Difference between revisions

Tag: wikieditor
 
(30 intermediate revisions by the same user not shown)
Line 1: Line 1:
Troubleshooting of MySQL errors
Troubleshooting of MySQL errors


{{LanguageSwitcher | content = [[Troubleshooting of MySQL errors | EN]], [[排除 MySQL 技術疑難問題|漢字]]}}
{{LanguageSwitcher | content = [[Troubleshooting of MySQL errors | English]], [[排除 MySQL 技術疑難問題|漢字]]}}
 
 
In this document, we explore various common issues encountered while working with MySQL, categorizing them into seven distinct groups based on their nature and impact. These categories help in identifying the underlying problems and facilitate efficient troubleshooting. The issues are classified as follows:
 
# '''Installation and Configuration Issues''': Problems related to setting up and configuring MySQL.
# '''Database and Table Operation Errors''': Issues during operations such as creating, dropping, or accessing databases and tables.
# '''Access and Authentication Errors''': Errors dealing with user permissions and authentication.
# '''SQL and Query Errors''': Issues related to the syntax and execution of SQL queries.
# '''Connection and Network Errors''': Problems involving connectivity between clients and the MySQL server.
# '''Resource and Environmental Errors''': Errors caused by system resources like disk space, memory limits, or file system permissions.
# '''Miscellaneous Tool-Specific Errors''': Errors specific to database tools like Navicat or issues from scripting environments like PHP.
 
Each category not only delineates common errors but also aids in the direct application of specific solutions tailored to each type of issue.


== Installation and Configuration Issues ==
== Installation and Configuration Issues ==
Line 42: Line 55:
* [https://mysqldump.guru/mysqldump-got-errno-32-on-write.html mysqldump: Got errno 32 on write | mysqldump.guru]
* [https://mysqldump.guru/mysqldump-got-errno-32-on-write.html mysqldump: Got errno 32 on write | mysqldump.guru]


== ERROR 1114 (HY000): The table `TABLE_NAME` is full ==
== Database and Table Operation Errors ==
Possible solution
 
* Because the hard disk of partition where [https://dev.mysql.com/doc/refman/5.7/en/data-directory.html MySQL Data Directory] located is full or almost full, free some hard disk space<ref>[http://stackoverflow.com/questions/730579/error-1114-hy000-the-table-is-full mysql - ERROR 1114 (HY000): The table is full - Stack Overflow]</ref>.
=== ERROR 1005 (HY000) at line xx: Can't create table 'TABLE_NAME' (errno: 28) ===
 
Solutions
* Check if the disk space where mysql data folder located is enough. e.g. Input {{kbd | key=df -h}} on {{Linux}}
* More on [http://stackoverflow.com/questions/11045279/error-1005-hy000-cant-create-table-errno-150 mysql - ERROR 1005 (HY000): Can't create table (errno: 150) - Stack Overflow].
 
=== ERROR 1006 (HY000): Can't create database 'DATABASE_NAME' (errno: 28) ===
Solutions
* Check if the disk space where mysql data folder located is enough. e.g. Input {{kbd | key=df -h}} on {{Linux}}
* More on [http://stackoverflow.com/questions/18719748/error-1006-hy000-cant-create-database-errno-13-mysql-5-6-12 ERROR 1006 (HY000) Can't create database (errno: 13) MySQL 5.6.12 - Stack Overflow].
 
=== ERROR 1010: Error dropping database (can't rmdir) ===
Message: <pre>Error dropping database (can't rmdir '.\<db_name>\', errno: 17)</pre>
 
Solution
* Manually delete the leftover non-MySQL files (e.g. .sql files) inside the database directory, then retry DROP DATABASE — or simply delete the entire folder manually.
 
Root Cause
* MySQL's DROP DATABASE only removes files it manages. Foreign files left in the data directory (such as .sql dumps) prevent rmdir from removing the folder, causing errno 17 (ENOTEMPTY).
 
=== ERROR 1017 - Can't find file: '.\DATABASE\TABLE.frm' (errno: 22 - Invalid argument) ===
Message: [Err] 1017 - Can't find file: '.\DATABASE\TABLE.frm' (errno: 22 - Invalid argument)
 
 
Solutions
* Check the existence of file DATABASE\TABLE.frm. If not, you may need to create the TABLE before executed the MySQL query.
* Check the permission of file DATABASE\TABLE.frm or folder which the file located<ref>[http://stackoverflow.com/questions/12106727/mysql-copying-tables-files-gives-rise-to-error-1017-hy000-cant-find-file MySQL, copying tables files gives rise to "ERROR 1017 (HY000): Can't find file:" even though its there there - Stack Overflow]</ref><ref>[https://www.percona.com/forums/questions-discussions/mysql-and-percona-server/2762-error-1017-hy000-can-t-find-file ERROR 1017 (HY000): Can't find file - Percona Community]</ref>. ''unverified''
 
=== Navicat error: Field doesn't have a default value ===
<pre>
[ERR] 1364 - Field 'source' doesn't have a default value
</pre>
 
Solution:
* When importing from Excel to a database, if the 'source' field is empty or not specified, it's necessary to assign a value to the 'source' field. Alternatively, modify the field definition to allow the field value to be NULL.
 
=== ERROR 1813: Tablespace for table xxx exists ===
Message: ERROR 1813 Tablespace for table xxx exists.
 
Solution
* [https://stackoverflow.com/questions/15694168/error-tablespace-for-table-xxx-exists-please-discard-the-tablespace-before-imp mysql - Error: Tablespace for table xxx exists. Please DISCARD the tablespace before IMPORT - Stack Overflow]
 
=== ERROR 1690 - BIGINT UNSIGNED value is out of range ===
Message: MySQL error #1690 (BIGINT UNSIGNED value is out of range)
 
Solution <ref>[https://dev.mysql.com/doc/refman/8.0/en/out-of-range-and-overflow.html MySQL :: MySQL 8.0 Reference Manual :: 11.2.6 Out-of-Range and Overflow Handling]</ref><ref>[https://stackoverflow.com/questions/34115917/mysql-error-1690-bigint-unsigned-value-is-out-of-range-for-unix-timestamp MySQL error #1690 (BIGINT UNSIGNED value is out of range) for UNIX_TIMESTAMP() - Stack Overflow]</ref>:
<pre>
SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';
</pre>
 
=== ERROR 1305 - FUNCTION MY_TABLE.MY_FUNCTION does not exist ===
Message: MySQL error 1305 - FUNCTION MY_TABLE.MY_FUNCTION does not exist


Solution: Fix the typo in the function name


== ERROR 1170: BLOB/TEXT column 'url' used in key specification without a key length ==
=== ERROR 1170: BLOB/TEXT column 'url' used in key specification without a key length ===
Condition
Condition
* SQL syntax when tried to create the new table
* SQL syntax when tried to create the new table
Line 82: Line 147:
</pre>
</pre>


== ERROR 1205: Lock wait timeout exceeded; try restarting transaction ==
=== Table already exists when using RENAME TABLE ===
Solution: <ref>[https://stackoverflow.com/questions/5836623/getting-lock-wait-timeout-exceeded-try-restarting-transaction-even-though-im mysql - Getting "Lock wait timeout exceeded; try restarting transaction" even though I'm not using a transaction - Stack Overflow]</ref>
# {{kbd | key=<nowiki>SHOW OPEN TABLES WHERE in_use > 0;</nowiki>}}<ref>[https://dev.mysql.com/doc/refman/5.7/en/show-open-tables.html MySQL :: MySQL 5.7 Reference Manual :: 13.7.5.24 SHOW OPEN TABLES Syntax]</ref>
# {{kbd | key=<nowiki>SHOW [FULL] PROCESSLIST;</nowiki>}}<ref>[https://dev.mysql.com/doc/refman/5.7/en/show-processlist.html MySQL :: MySQL 5.7 Reference Manual :: 13.7.5.29 SHOW PROCESSLIST Syntax]</ref>
# {{kbd | key=<nowiki>KILL <process id>;</nowiki>}}<ref>[https://dev.mysql.com/doc/refman/5.7/en/kill.html MySQL :: MySQL 5.7 Reference Manual :: 13.7.6.4 KILL Syntax]</ref>
 
Related article
* [https://errerrors.blogspot.com/2022/10/how-to-fix-lock-wait-timeout-exceeded-try-restarting-transaction-on-mysql.html 解決 MySQL ERROR 1205: Lock wait timeout exceeded; try restarting transaction]


== ERROR 1206: The total number of locks exceeds the lock table size ==
Situation: When replacing a table across databases using <code>RENAME TABLE</code>, the following error occurs even after renaming the existing table as a backup:
Message: Error Code: 1206. The total number of locks exceeds the lock table size


Current condition<ref>[https://dev.mysql.com/doc/refman/8.0/en/show-variables.html MySQL :: MySQL 8.0 Reference Manual :: 13.7.6.39 SHOW VARIABLES Syntax]</ref>:
<pre lang="text">
* Keywin {{kbd | key = <nowiki>SHOW VARIABLES LIKE 'innodb_buffer_pool_size';</nowiki>}}. If it returns {{kbd | key=8388608}}, it means {{kbd | key=8388608}} bytes ≅ 8MB.
Table '.\DATABASE_NAME\TABLE_NAME' already exists
</pre>


Solution:  
Possible cause: The source and destination tables have the same foreign key constraint name. Renaming the existing table leaves its custom constraint name unchanged, causing a naming conflict when the new table is moved into the destination database. MySQL 5.7, 8.0, and 8.4 require foreign key constraint names to be unique within a database. See [https://docs.oracle.com/cd/E17952_01/mysql-5.7-en/create-table-foreign-keys.html MySQL Foreign Key Constraints].
* Increase {{kbd | key = innodb_buffer_pool_size}} e.g. {{kbd | key =<nowiki>SET GLOBAL innodb_buffer_pool_size=402653184;</nowiki>}} (402653184 bytes ~ 400MB. Default value is 8MB.)
* Reduce the size of query data


Further reading:
Solution:
* [http://stackoverflow.com/questions/5696857/how-to-change-value-for-innodb-buffer-pool-size-in-mysql-on-mac-os innodb - How to change value for innodb_buffer_pool_size in MySQL on Mac OS? - Stack Overflow].
* [https://dev.mysql.com/doc/refman/5.7/en/innodb-buffer-pool-resize.html MySQL :: MySQL 5.7 Reference Manual :: 14.6.3.2 Configuring InnoDB Buffer Pool Size]


== ERROR 1235: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' ==
'''1. Confirm that the backup table name is available, and check the foreign key names on both tables.'''
Message: ERROR 1235 (42000): This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'.


Solution: Change the syntax of subquery to {{kbd | key =column_name BETWEEN start_number to end_number}}
<pre lang="sql">
SHOW CREATE TABLE target_db.example_items;
SHOW CREATE TABLE staging_db.example_items;
</pre>


Further reading:
Look for <code>FOREIGN KEY</code> in the output. For example:
* [https://dev.mysql.com/doc/mysql-reslimits-excerpt/5.6/en/subquery-restrictions.html MySQL :: MySQL Restrictions and Limitations :: 4 Restrictions on Subqueries]


== Database and Table Operation Errors ==
<pre lang="sql">
KEY `ix_example_parent_id` (`parent_id`),


=== ERROR 1005 (HY000) at line xx: Can't create table 'TABLE_NAME' (errno: 28) ===
CONSTRAINT `fk_example_parent`
  FOREIGN KEY (`parent_id`)
  REFERENCES `example_parents` (`id`)
  ON DELETE SET NULL
</pre>


Solutions
<table>
* Check if the disk space where mysql data folder located is enough. e.g. Input {{kbd | key=df -h}} on {{Linux}}
<tr><th>Syntax</th><th>Meaning</th></tr>
* More on [http://stackoverflow.com/questions/11045279/error-1005-hy000-cant-create-table-errno-150 mysql - ERROR 1005 (HY000): Can't create table (errno: 150) - Stack Overflow].
<tr><td><code>KEY ...</code></td><td>An index; '''this alone does not indicate a foreign key'''</td></tr>
<tr><td><code>CONSTRAINT fk_example_parent</code></td><td>The foreign key constraint name, used when dropping the foreign key</td></tr>
<tr><td><code>FOREIGN KEY (parent_id)</code></td><td>The foreign key column in this table</td></tr>
<tr><td><code>REFERENCES example_parents (id)</code></td><td>The referenced parent table and column</td></tr>
<tr><td><code>ON DELETE SET NULL</code></td><td>Sets the corresponding foreign key value to <code>NULL</code> when the referenced parent row is deleted</td></tr>
</table>


=== ERROR 1006 (HY000): Can't create database 'DATABASE_NAME' (errno: 28) ===
An <code>fk_</code> prefix alone does not identify a foreign key. Look for <code>FOREIGN KEY (...) REFERENCES ...</code> to confirm.
Solutions
* Check if the disk space where mysql data folder located is enough. e.g. Input {{kbd | key=df -h}} on {{Linux}}
* More on [http://stackoverflow.com/questions/18719748/error-1006-hy000-cant-create-database-errno-13-mysql-5-6-12 ERROR 1006 (HY000) Can't create database (errno: 13) MySQL 5.6.12 - Stack Overflow].


=== ERROR 1017 - Can't find file: '.\DATABASE\TABLE.frm' (errno: 22 - Invalid argument) ===
Also, <code>SHOW CREATE TABLE</code> lists only foreign keys defined on that table. It does not list foreign keys in other tables that reference it.
Message: [Err] 1017 - Can't find file: '.\DATABASE\TABLE.frm' (errno: 22 - Invalid argument)


'''2. If the foreign key constraint is unnecessary, drop the conflicting constraint from the existing destination table, then swap the tables.'''


Solutions
<pre lang="sql">
* Check the existence of file DATABASE\TABLE.frm. If not, you may need to create the TABLE before executed the MySQL query.
ALTER TABLE target_db.example_items
* Check the permission of file DATABASE\TABLE.frm or folder which the file located<ref>[http://stackoverflow.com/questions/12106727/mysql-copying-tables-files-gives-rise-to-error-1017-hy000-cant-find-file MySQL, copying tables files gives rise to "ERROR 1017 (HY000): Can't find file:" even though its there there - Stack Overflow]</ref><ref>[https://www.percona.com/forums/questions-discussions/mysql-and-percona-server/2762-error-1017-hy000-can-t-find-file ERROR 1017 (HY000): Can't find file - Percona Community]</ref>. ''unverified''
  DROP FOREIGN KEY fk_example_parent;


=== Navicat error: Field doesn't have a default value ===
RENAME TABLE
<pre>
  target_db.example_items TO target_db.example_items_backup,
[ERR] 1364 - Field 'source' doesn't have a default value
  staging_db.example_items TO target_db.example_items;
</pre>
</pre>


Solution:
Notes:
* When importing from Excel to a database, if the 'source' field is empty or not specified, it's necessary to assign a value to the 'source' field. Alternatively, modify the field definition to allow the field value to be NULL.


=== ERROR 1813: Tablespace for table xxx exists ===
* Dropping the foreign key preserves the column and index, but removes referential integrity checks and the original <code>ON DELETE SET NULL</code> behavior.
Message: ERROR 1813 Tablespace for table xxx exists.
* If the foreign key is required, recreate the constraint with a different name.
* After the swap, verify which database the foreign key references. Foreign keys in other tables follow the renamed old table; they do not automatically switch to the replacement table. See [https://docs.percona.com/percona-toolkit/pt-online-schema-change.html Percona’s Foreign Key Handling Documentation].


Solution
== Access and Authentication Errors ==
* [https://stackoverflow.com/questions/15694168/error-tablespace-for-table-xxx-exists-please-discard-the-tablespace-before-imp mysql - Error: Tablespace for table xxx exists. Please DISCARD the tablespace before IMPORT - Stack Overflow]


=== ERROR 1690 - BIGINT UNSIGNED value is out of range ===
=== [Warning] Using a password on the command line interface can be insecure ===
Message: MySQL error #1690 (BIGINT UNSIGNED value is out of range)
Problem Description:  
When exporting or importing MySQL databases via bash commands, you may encounter the following warning:


Solution <ref>[https://dev.mysql.com/doc/refman/8.0/en/out-of-range-and-overflow.html MySQL :: MySQL 8.0 Reference Manual :: 11.2.6 Out-of-Range and Overflow Handling]</ref><ref>[https://stackoverflow.com/questions/34115917/mysql-error-1690-bigint-unsigned-value-is-out-of-range-for-unix-timestamp MySQL error #1690 (BIGINT UNSIGNED value is out of range) for UNIX_TIMESTAMP() - Stack Overflow]</ref>:
<pre>
<pre>
SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';
mysql: [Warning] Using a password on the command line interface can be insecure.
 
or
 
mysqldump: [Warning] Using a password on the command line interface can be insecure.
</pre>
</pre>


=== ERROR 1305 - FUNCTION MY_TABLE.MY_FUNCTION does not exist ===
This typically occurs when using commands like:
Message: MySQL error 1305 - FUNCTION MY_TABLE.MY_FUNCTION does not exist
 
<pre>
mysqldump -u USERNAME -p -h 127.0.0.1 --default-character-set=utf8 DATABASE > DATABASE.sql
</pre>


Solution: Fix the typo in the function name
Solution: To resolve this warning and improve security, follow these steps:
# Set up a login path using [https://dev.mysql.com/doc/refman/8.4/en/mysql-config-editor.html mysql_config_editor]: {{kbd | key=<nowiki>mysql_config_editor set --login-path=local --host=localhost --user=root --password</nowiki>}}
# Use the login path when exporting or importing MySQL databases (1) For exporting: {{kbd | key=<nowiki>mysqldump --login-path=local --default-character-set=utf8 DATABASE > DATABASE.sql</nowiki>}} (2) For importing: {{kbd | key=<nowiki>pv DATABASE.sql.gz | gunzip | mysql --login-path=local --default_character_set utf8 --force DATABASE</nowiki>}}
# To view all configured login paths {{kbd | key=<nowiki>mysql_config_editor print --all</nowiki>}}


== Access and Authentication Errors ==
By using a login path, you avoid exposing your password in the command line, thus resolving the security warning.


=== ERROR 1044 (42000): Access denied for user 'USER'@'localhost' to database 'DATABASE_NAME' ===
=== ERROR 1044 (42000): Access denied for user 'USER'@'localhost' to database 'DATABASE_NAME' ===
Line 276: Line 347:
) final
) final
WHERE final.rank <= 10
WHERE final.rank <= 10
</pre>
=== ERROR 1055: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ===
Message
<pre>
Query Error (1055): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.posts.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
</pre>
Query with Error
<pre>
-- Create sample table
CREATE TABLE posts (
  id INT,
  post_id VARCHAR(10),
  author VARCHAR(50),
  content TEXT,
  likes INT,
  post_time DATETIME
);
-- Insert sample data
INSERT INTO posts VALUES
(1, 'A123', 'Alice', 'First post', 10, '2024-01-01'),
(2, 'A123', 'Bob', 'Great!', 5, '2024-01-02'),
(3, 'A123', 'Bob', 'Nice!', 3, '2024-01-03');
-- This will cause an error
SELECT
  id,          -- Problem: Not in GROUP BY
  post_id,
  author,
  GROUP_CONCAT(content SEPARATOR "\n") AS content,    -- This is OK as it uses aggregate function
  likes        -- Problem: Not in GROUP BY
FROM posts
GROUP BY post_id, author;
</pre>
Solution: Fix the query by either (1) including all columns in GROUP BY or (2) using aggregate functions (like MAX, MIN, SUM, COUNT, GROUP_CONCAT)
<pre>
-- Method 1: disable `sql_mode=only_full_group_by`
```
There are two ways to disable `sql_mode=only_full_group_by`:
1. Temporary Change (Only affects current session)
```sql
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
```
2. Permanent Change (Modify MySQL configuration file)
- Locate MySQL configuration file (usually `my.cnf` or `my.ini`)
- Add or modify in the `[mysqld]` section:
```ini
[mysqld]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
```
Important Notes:
1. After modifying the configuration file, MySQL service needs to be restarted to take effect
2. Disabling this setting is not recommended because:
  - May lead to unpredictable query results
  - Violates SQL standards
  - May cause compatibility issues in future versions
The recommended approach is to fix the SQL query rather than changing the SQL mode.
```
-- Method 2: Add all columns to GROUP BY
SELECT
  id,
  post_id,
  author,
  content,
  likes
FROM posts
GROUP BY post_id, author, id, content, likes;
-- Method 3: Use aggregate functions for non-GROUP BY columns 
SELECT
  MAX(id) as id,
  post_id,
  author,
  GROUP_CONCAT(content) as contents,
  SUM(likes) as total_likes
FROM posts
GROUP BY post_id, author;
</pre>
</pre>


Line 335: Line 492:


Solution: {{kbd | key =<nowiki>SELECT CONCAT(`string_column`, CONVERT(`int_column`, CHAR))</nowiki>}} or {{kbd | key =<nowiki>SELECT CONCAT(`string_column`, CAST(`int_column` AS CHAR))</nowiki>}}<ref>[https://stackoverflow.com/questions/15368753/cast-int-to-varchar mysql - Cast int to varchar - Stack Overflow]</ref><ref>[http://blog.51cto.com/bian5399/1092772 mysql字符集问题:Illegal mix of collations-每天让自己进步一点-51CTO博客]</ref>
Solution: {{kbd | key =<nowiki>SELECT CONCAT(`string_column`, CONVERT(`int_column`, CHAR))</nowiki>}} or {{kbd | key =<nowiki>SELECT CONCAT(`string_column`, CAST(`int_column` AS CHAR))</nowiki>}}<ref>[https://stackoverflow.com/questions/15368753/cast-int-to-varchar mysql - Cast int to varchar - Stack Overflow]</ref><ref>[http://blog.51cto.com/bian5399/1092772 mysql字符集问题:Illegal mix of collations-每天让自己进步一点-51CTO博客]</ref>
=== ERROR 1235: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' ===
Message: ERROR 1235 (42000): This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'.
Solution: Change the syntax of subquery to {{kbd | key =column_name BETWEEN start_number to end_number}}
Further reading:
* [https://dev.mysql.com/doc/mysql-reslimits-excerpt/5.6/en/subquery-restrictions.html MySQL :: MySQL Restrictions and Limitations :: 4 Restrictions on Subqueries]
=== Error: MySQL Incorrect datetime value: '0000-00-00 00:00:00' ===
Workaround solution<ref>[https://stackoverflow.com/questions/35565128/mysql-incorrect-datetime-value-0000-00-00-000000 MySQL Incorrect datetime value: '0000-00-00 00:00:00' - Stack Overflow]</ref>:
<pre>
SET SQL_MODE='ALLOW_INVALID_DATES';
</pre>
=== Optimization Solutions for Query Performance ===
Originally, product_id (VARCHAR, 200) was used as the primary key. When the data volume reached approximately 600,000, data processing became very slow. Adding a field id (int) as the primary key can solve the problem of slow query speed.


== Connection and Network Errors ==
== Connection and Network Errors ==
Line 413: Line 589:
</pre>
</pre>
* If still not work, reboot the server and restart the MySQL service.
* If still not work, reboot the server and restart the MySQL service.
=== SQLSTATE[HY000] [2002] Can't assign requested address ===
Error message
<pre>
Caught PDOException: /path/to/script.php ERROR: Cannot connect: SQLSTATE[HY000] [2002] Can't assign requested address
utf8: SQLSTATE[HY000] [2002] Can't assign requested address
Caught PDOException: /path/to/script.php ERROR: Cannot connect: SQLSTATE[HY000] [2002] Operation timed out
utf8: SQLSTATE[HY000] [2002] Operation timed out
</pre>
Walkaround Solution:
* You can extend the interval between each MySQL save operation.
Explanation:
It typically occurs when your application is unable to establish a connection to the specified database server.
=== Resolving "Host 'xx.xx.xxx.xxx' is blocked because of many connection errors" ===
Error Message
<pre>
Host 'xx.xx.xxx.xxx' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
</pre>
Understanding the Issue
(1) Check the threshold value
MySQL's mechanism works as follows: once the same source host (identified by IP or hostname) accumulates a number of "connection errors" reaching the value configured in `max_connect_errors`, MySQL automatically blocks that source and refuses further connections from it.
<pre>
SHOW VARIABLES LIKE 'max_connect_errors';
</pre>
The threshold found was 100.
(2) Check which hosts are currently recorded/blocked
<pre>
SELECT IP, HOST, SUM_CONNECT_ERRORS, COUNT_HOST_BLOCKED_ERRORS
FROM performance_schema.host_cache
ORDER BY SUM_CONNECT_ERRORS DESC;
</pre>
Confirmed that the only blocked IP is `xx.xx.xxx.xxx`, with `SUM_CONNECT_ERRORS` exactly matching the threshold of 100, and no other IPs were affected.
Resolving the Issue
⚠️ Note: `flush-hosts` / `FLUSH HOSTS` clears the **entire** host cache, not just a single IP. If the query results show records for other hosts as well, they will all be reset at the same time. For a shared production environment, it's recommended to confirm with other administrators before running this.
(1) In a terminal or command prompt, run:
<pre>
mysqladmin -u root -p flush-hosts
</pre>
or
<pre>
mysql -u root -p
Once inside the MySQL shell, run: FLUSH HOSTS;
</pre>
Note: The `FLUSH HOSTS` syntax has been deprecated since MySQL 8.0.23 and removed in 8.4<ref>[https://dev.mysql.com/doc/refman/8.4/en/performance-schema-host-cache-table.html MySQL :: MySQL 8.4 Reference Manual :: 29.12.22.3 The host_cache Table]</ref><ref>[https://oneuptime.com/blog/post/2026-03-31-mysql-fix-max-connect-errors-blocked-hosts/view How to Fix max_connect_errors and Blocked Hosts in MySQL]</ref>. If your environment is on a newer version, use the officially recommended alternative instead:
<pre>
TRUNCATE TABLE performance_schema.host_cache;
</pre>
(2) Verify after execution
<pre>
SELECT IP, HOST, SUM_CONNECT_ERRORS, COUNT_HOST_BLOCKED_ERRORS
FROM performance_schema.host_cache
ORDER BY SUM_CONNECT_ERRORS DESC;
</pre>
Result: no rows returned (0 rows), indicating the host cache has been cleared — the previous connection error counts and blocked status have been reset, and the IP should now be able to connect normally.
=== Transfer Data from MySQL to MSSQL ===
Condition: Need to synchronize or transfer data from MySQL database to Microsoft SQL Server.
Solution:
* (Manually method) Export MySQL data in a format compatible with Microsoft SQL Server: {{kbd | key=<nowiki>mysqldump --compatible=mssql [database_name]</nowiki>}}<ref>[https://dev.mysql.com/doc/refman/8.4/en/mysqldump.html#option_mysqldump_compatible MySQL :: MySQL 8.4 Reference Manual :: 6.5.4 mysqldump — A Database Backup Program]</ref>
* (Automated method) Use [https://learn.microsoft.com/en-us/sql/ssma/sql-server-migration-assistant?view=sql-server-ver17 Microsoft SQL Server Migration Assistant] or ''$'' [https://www.webyog.com/product/sqlyog SQLyog] tool (for {{Win}}). Use query commands to specify the data to be transferred from MS SQL server to MySQL server.
Example mysqldump command
<pre>
mysqldump -h 127.0.0.1 -u root -p \
  --skip-lock-tables \
  --single-transaction \
  --default-character-set=utf8 \
  --compatible=mssql \
  --skip-extended-insert \
  --no-auto-rehash \
  --skip-comments \
  database_name > database_name.sql
</pre>
Related issues:
* For large data volumes, connection timeout issues may occur. In such cases, refer to Error 2013 handling methods by increasing connection timeout settings or processing data in batches.
* The two database systems have differences in data types, so data compatibility should be verified before transfer.


== Resource and Environmental Errors ==
== Resource and Environmental Errors ==
Line 451: Line 731:


=== MySQL server has gone away ===
=== MySQL server has gone away ===
steps
Error conditions:
* Enable the option {{kbd | key = log_error}} in MySQL config file e.g. {{kbd | key = <nowiki>log_error="file_name_of_error_log"</nowiki>}}<ref>[https://dev.mysql.com/doc/refman/8.0/en/error-log.html MySQL :: MySQL 8.0 Reference Manual :: 5.4.2 The Error Log]</ref>.
* Enable the option {{kbd | key = log_error}} in MySQL config file e.g. {{kbd | key = <nowiki>log_error="file_name_of_error_log"</nowiki>}}<ref>[https://dev.mysql.com/doc/refman/8.0/en/error-log.html MySQL :: MySQL 8.0 Reference Manual :: 5.4.2 The Error Log]</ref>.
* Example error log located at {{kbd | key = <nowiki>file_name_of_error_log</nowiki>}} are as following:
* Example error log located at {{kbd | key = <nowiki>file_name_of_error_log</nowiki>}} are as following:
Line 458: Line 738:
2019-05-23T08:52:19.989876Z 99980 [Note] Aborted connection 99980 to db: 'DB_NAME' user: 'DB_USER' host: 'localhost' (Got a packet bigger than 'max_allowed_packet' bytes)
2019-05-23T08:52:19.989876Z 99980 [Note] Aborted connection 99980 to db: 'DB_NAME' user: 'DB_USER' host: 'localhost' (Got a packet bigger than 'max_allowed_packet' bytes)
</pre>
</pre>
Solution:


* Increase the value of {{kbd | key = <nowiki>max_allowed_packet</nowiki>}}<ref>[https://stackoverflow.com/questions/5688403/how-to-check-and-set-max-allowed-packet-mysql-variable php - how to check and set max_allowed_packet mysql variable - Stack Overflow]</ref> if the MySQL user has the {{kbd | key = <nowiki>SUPER</nowiki>}} privilege<ref>[https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html MySQL :: MySQL 8.0 Reference Manual :: 6.2.2 Privileges Provided by MySQL]</ref>.
* Increase the value of {{kbd | key = <nowiki>max_allowed_packet</nowiki>}}<ref>[https://stackoverflow.com/questions/5688403/how-to-check-and-set-max-allowed-packet-mysql-variable php - how to check and set max_allowed_packet mysql variable - Stack Overflow]</ref> if the MySQL user has the {{kbd | key = <nowiki>SUPER</nowiki>}} privilege<ref>[https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html MySQL :: MySQL 8.0 Reference Manual :: 6.2.2 Privileges Provided by MySQL]</ref>.
Line 489: Line 771:
Validation
Validation
* Query the syntax {{kbd | key=<nowiki>SHOW VARIABLES LIKE 'tmpdir';</nowiki>}} to validate the modification of mysql configuration file.
* Query the syntax {{kbd | key=<nowiki>SHOW VARIABLES LIKE 'tmpdir';</nowiki>}} to validate the modification of mysql configuration file.
=== errno 11 - Resource temporarily unavailable ===
Message: '''Can't create a new thread (errno 11 "Resource temporarily unavailable")'''
Solution: [https://duntuk.com/how-raise-ulimit-open-files-and-mysql-openfileslimit How to permanently raise ulimit 'open files' and MySQL 'open_files_limit']


=== errno 41 - Error dropping database ===
=== errno 41 - Error dropping database ===
Line 519: Line 806:


solution: Using the naive mysqldump command to generate the backup file. And import the backup by using mysql command.
solution: Using the naive mysqldump command to generate the backup file. And import the backup by using mysql command.
=== ERROR 1206: The total number of locks exceeds the lock table size ===
Message: Error Code: 1206. The total number of locks exceeds the lock table size
Current condition<ref>[https://dev.mysql.com/doc/refman/8.0/en/show-variables.html MySQL :: MySQL 8.0 Reference Manual :: 13.7.6.39 SHOW VARIABLES Syntax]</ref>:
* Keywin {{kbd | key = <nowiki>SHOW VARIABLES LIKE 'innodb_buffer_pool_size';</nowiki>}}. If it returns {{kbd | key=8388608}}, it means {{kbd | key=8388608}} bytes ≅ 8MB.
Solution:
* Increase {{kbd | key = innodb_buffer_pool_size}} e.g. {{kbd | key =<nowiki>SET GLOBAL innodb_buffer_pool_size=402653184;</nowiki>}} (402653184 bytes ~ 400MB. Default value is 8MB.)
* Reduce the size of query data
Further reading:
* [http://stackoverflow.com/questions/5696857/how-to-change-value-for-innodb-buffer-pool-size-in-mysql-on-mac-os innodb - How to change value for innodb_buffer_pool_size in MySQL on Mac OS? - Stack Overflow].
* [https://dev.mysql.com/doc/refman/5.7/en/innodb-buffer-pool-resize.html MySQL :: MySQL 5.7 Reference Manual :: 14.6.3.2 Configuring InnoDB Buffer Pool Size]
=== ERROR 1205: Lock wait timeout exceeded; try restarting transaction ===
Solution: <ref>[https://stackoverflow.com/questions/5836623/getting-lock-wait-timeout-exceeded-try-restarting-transaction-even-though-im mysql - Getting "Lock wait timeout exceeded; try restarting transaction" even though I'm not using a transaction - Stack Overflow]</ref>
# {{kbd | key=<nowiki>SHOW OPEN TABLES WHERE in_use > 0;</nowiki>}}<ref>[https://dev.mysql.com/doc/refman/5.7/en/show-open-tables.html MySQL :: MySQL 5.7 Reference Manual :: 13.7.5.24 SHOW OPEN TABLES Syntax]</ref>
# {{kbd | key=<nowiki>SHOW [FULL] PROCESSLIST;</nowiki>}}<ref>[https://dev.mysql.com/doc/refman/5.7/en/show-processlist.html MySQL :: MySQL 5.7 Reference Manual :: 13.7.5.29 SHOW PROCESSLIST Syntax]</ref>
# {{kbd | key=<nowiki>KILL <process id>;</nowiki>}}<ref>[https://dev.mysql.com/doc/refman/5.7/en/kill.html MySQL :: MySQL 5.7 Reference Manual :: 13.7.6.4 KILL Syntax]</ref>
Related article
* [https://errerrors.blogspot.com/2022/10/how-to-fix-lock-wait-timeout-exceeded-try-restarting-transaction-on-mysql.html 解決 MySQL ERROR 1205: Lock wait timeout exceeded; try restarting transaction]
=== ERROR 1114 (HY000): The table `TABLE_NAME` is full ===
Possible solution
* Because the hard disk of partition where [https://dev.mysql.com/doc/refman/5.7/en/data-directory.html MySQL Data Directory] located is full or almost full, free some hard disk space<ref>[http://stackoverflow.com/questions/730579/error-1114-hy000-the-table-is-full mysql - ERROR 1114 (HY000): The table is full - Stack Overflow]</ref>.


== Miscellaneous Tool-Specific Errors ==
== Miscellaneous Tool-Specific Errors ==
Line 590: Line 904:
solution:
solution:
* LIMIT the rows of MySQL query
* LIMIT the rows of MySQL query
== Further Reading ==
* If you cannot find the answer you're looking for, you can visit [https://stackoverflow.com/questions/tagged/mysql Unanswered 'mysql' Questions - Stack Overflow]


== References ==
== References ==
<references/>
<references/>


{{Template:Troubleshooting}}
{{Template:Data factory flow}}


[[Category:MySQL]]
[[Category: MySQL]]
[[Category:Database]]
[[Category: Database]]
[[Category:Data Science]]
[[Category: Data Science]]
[[Category: Revised with LLMs]]