Troubleshooting of MySQL errors: Difference between revisions
Tag: wikieditor |
|||
| (7 intermediate revisions by the same user not shown) | |||
| Line 67: | Line 67: | ||
* Check if the disk space where mysql data folder located is enough. e.g. Input {{kbd | key=df -h}} on {{Linux}} | * 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]. | * 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) === | === ERROR 1017 - Can't find file: '.\DATABASE\TABLE.frm' (errno: 22 - Invalid argument) === | ||
| Line 137: | Line 146: | ||
/*!40101 SET character_set_client = @saved_cs_client */; | /*!40101 SET character_set_client = @saved_cs_client */; | ||
</pre> | </pre> | ||
=== Table already exists when using RENAME TABLE === | |||
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: | |||
<pre lang="text"> | |||
Table '.\DATABASE_NAME\TABLE_NAME' already exists | |||
</pre> | |||
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]. | |||
Solution: | |||
'''1. Confirm that the backup table name is available, and check the foreign key names on both tables.''' | |||
<pre lang="sql"> | |||
SHOW CREATE TABLE target_db.example_items; | |||
SHOW CREATE TABLE staging_db.example_items; | |||
</pre> | |||
Look for <code>FOREIGN KEY</code> in the output. For example: | |||
<pre lang="sql"> | |||
KEY `ix_example_parent_id` (`parent_id`), | |||
CONSTRAINT `fk_example_parent` | |||
FOREIGN KEY (`parent_id`) | |||
REFERENCES `example_parents` (`id`) | |||
ON DELETE SET NULL | |||
</pre> | |||
<table> | |||
<tr><th>Syntax</th><th>Meaning</th></tr> | |||
<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> | |||
An <code>fk_</code> prefix alone does not identify a foreign key. Look for <code>FOREIGN KEY (...) REFERENCES ...</code> to confirm. | |||
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. | |||
'''2. If the foreign key constraint is unnecessary, drop the conflicting constraint from the existing destination table, then swap the tables.''' | |||
<pre lang="sql"> | |||
ALTER TABLE target_db.example_items | |||
DROP FOREIGN KEY fk_example_parent; | |||
RENAME TABLE | |||
target_db.example_items TO target_db.example_items_backup, | |||
staging_db.example_items TO target_db.example_items; | |||
</pre> | |||
Notes: | |||
* Dropping the foreign key preserves the column and index, but removes referential integrity checks and the original <code>ON DELETE SET NULL</code> behavior. | |||
* 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]. | |||
== Access and Authentication Errors == | == Access and Authentication Errors == | ||
| Line 538: | Line 607: | ||
It typically occurs when your application is unable to establish a connection to the specified database server. | 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 === | === Transfer Data from MySQL to MSSQL === | ||
| Line 543: | Line 674: | ||
Solution: | Solution: | ||
* (Manually method) Export MySQL data in a format compatible with Microsoft SQL Server: {{kbd | key=<nowiki>mysqldump --compatible=mssql [database_name]</nowiki>}} | * (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://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. | * (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: | Related issues: | ||
| Line 627: | 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 762: | Line 911: | ||
<references/> | <references/> | ||
{{Template: | {{Template:Data factory flow}} | ||
[[Category: MySQL]] | [[Category: MySQL]] | ||