Editing
Troubleshooting of MySQL errors
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
Troubleshooting of MySQL errors {{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 == === command not found: mysqldump === # locate the mysqldump command #* Key-in the command {{kbd | key=<nowiki>sudo find / -iname mysqldump</nowiki>}} for {{Mac}} or {{Linux}} #* If you installed #** [https://www.apachefriends.org/index.html XAMPP] for {{Mac}}: Entire path is {{kbd | key=<nowiki>/Applications/XAMPP/xamppfiles/bin/mysqldump</nowiki>}} #** [https://www.apachefriends.org/index.html XAMPP] on X disk for {{Win}}: Entire path is {{kbd | key=<nowiki>X:\xampp\mysql\bin\mysqldump.exe</nowiki>}} #** [https://www.mamp.info/en/ MAMP & ''$'' MAMP PRO] for {{Mac}}: Entire path is {{kbd | key=<nowiki>/Applications/MAMP/Library/bin/mysqldump</nowiki>}} # input the complete path of mysqldump command #* old command which caused error {{kbd | key=<nowiki>mysqldump -h 127.0.0.1 -u root -p --force --single-transaction DATABASE_NAME | pv | gzip -c > DATABASE_NAME.sql.gz</nowiki>}} #* new command {{kbd | key=<nowiki>/Applications/XAMPP/xamppfiles/bin/mysqldump -h 127.0.0.1 -u root -p --force --single-transaction DATABASE_NAME | pv | gzip -c > DATABASE_NAME.sql.gz</nowiki>}} === Could not start MySQL service on Windows === checklist # [https://dev.mysql.com/doc/refman/5.7/en/data-directory.html MySQL Data Directory] was allowed to written by {{kbd | key=NETWORK SERVICE}} on Windows Server 2008<ref>[https://errerrors.blogspot.com/2016/12/mysql-windows-server-2008-r2.html 如何修改 MySQL 伺服器的資料目錄 (Windows Server 2008 R2)]</ref> # Directory {{kbd | key=secure-file-priv}} was allowed to written by {{kbd | key=NETWORK SERVICE}} on Windows Server 2008 === mysqldump: Got errno 32 on write === Error condition <pre> $ mysqldump -h localhost -u root -p --force --single-transaction --default-character-set=utf8 --quick mytable | pv | gzip -c > mytable.sql.gz </pre> met the error message: <pre> -bash: pv: command not found ... mysqldump: Got errno 32 on write </pre> Root cause * The pv was not installed * Input the command to check if pv was installed {{kbd | key=which pv}} * install pv by input the command: {{kbd | key=sudo yum -y install pv}} <ref>[https://installati.one/centos/7/pv/ How To Install pv on CentOS 7 | Installati.one]</ref> References * [https://mysqldump.guru/mysqldump-got-errno-32-on-write.html mysqldump: Got errno 32 on write | mysqldump.guru] == Database and Table Operation Errors == === 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 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 === Condition * SQL syntax when tried to create the new table <pre> DROP TABLE IF EXISTS `my_table`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `my_table` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `url` text COLLATE utf8mb4_unicode_ci NOT NULL, `status` tinyint(2) unsigned NOT NULL DEFAULT 1, PRIMARY KEY (`job_id`), UNIQUE KEY `url` (`url`) USING HASH ) ENGINE=InnoDB AUTO_INCREMENT=3573 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; </pre> Solution: BLOB/TEXT column 'url' used in key specification with a key length e.g. {{kbd | key=`url`(500)}} <pre> DROP TABLE IF EXISTS `my_table`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `my_table` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `url` text COLLATE utf8mb4_unicode_ci NOT NULL, `status` tinyint(2) unsigned NOT NULL DEFAULT 1, PRIMARY KEY (`id`), UNIQUE KEY `url` (`url`(500)) ) ENGINE=InnoDB AUTO_INCREMENT=3573 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; </pre> == Access and Authentication Errors == === [Warning] Using a password on the command line interface can be insecure === Problem Description: When exporting or importing MySQL databases via bash commands, you may encounter the following warning: <pre> 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> This typically occurs when using commands like: <pre> mysqldump -u USERNAME -p -h 127.0.0.1 --default-character-set=utf8 DATABASE > DATABASE.sql </pre> 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>}} 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' === Message: {{kbd | key=<nowiki>ERROR 1044 (42000): Access denied for user 'USER'@'localhost' to database 'DATABASE_NAME'</nowiki>}} <pre> pv file.sql.gz | gunzip | mysql -u USER -p --host=127.0.0.1 --default_character_set utf8 DATABASE_NAME </pre> Solution: * Check the permission of specified user name & database name <pre> $ mysql -u USER -p --host=127.0.0.1 Enter password: mysql> use DATABASE_NAME </pre> Message: {{kbd | key=<nowiki>mysqldump: Got error: 1044: Access denied for user 'USER'@'localhost' to database 'DATABASE_NAME' when doing LOCK TABLES</nowiki>}} <pre> $ mysqldump -h 127.0.0.1 -u USER -p DATABASE_NAME TABLE_NAME > TABLE_NAME.sql </pre> Solution: * Add the mysqldump option {{kbd | key=<nowiki>--skip-lock-tables</nowiki>}} if you cannot grant the user permissions <ref>[https://stackoverflow.com/questions/7415698/skip-lock-tables-and-mysqldump mysql - skip-lock-tables and mysqldump - Stack Overflow]</ref>. <pre> $ mysqldump -h 127.0.0.1 -u USER -p --skip-lock-tables DATABASE_NAME TABLE_NAME > TABLE_NAME.sql </pre> === Error!: SQLSTATE[28000]: Invalid authorization specification: 1045 Access denied === Message: Error!: {{kbd | key=<nowiki>SQLSTATE[28000]: Invalid authorization specification: 1045 Access denied for user 'user'@'localhost' (using password: YES)</nowiki>}} Solution: * If you executed the query{{kbd | key=INTO OUTFILE}}, you need to grant the file permission e.g. {{kbd | key=GRANT FILE ON *.* TO 'user'@'localhost';}}<ref>[https://dev.mysql.com/doc/refman/5.7/en/privileges-provided.html#priv_file MySQL :: MySQL 5.7 Reference Manual :: 6.2.1 Privileges Provided by MySQL]</ref><ref>[https://stackoverflow.com/questions/6091427/mysql-into-outfile-access-denied-but-my-user-has-all-access-and-the-fold MYSQL into outfile "access denied" - but my user has "ALL" access.. and the folder is CHMOD 777 - Stack Overflow]</ref>. Related issue: "Error!: SQLSTATE[HY000]: General error: 1290 The MySQL server is running with the --secure-file-priv option so it cannot execute this statement"<ref>[https://stackoverflow.com/questions/32737478/how-should-i-tackle-secure-file-priv-in-mysql database - How should I tackle --secure-file-priv in MySQL? - Stack Overflow]</ref> === ERROR 1049 (42000): Unknown database === Message: ERROR 1049 (42000): Unknown database 'MY_DATABASE_p' Solution: * Check the database 'MY_DATABASE_p' is exists * Check there are no {{kbd | key=TAB}} character after database name if you want to connect the database 'MY_DATABASE' when you are using console. === ERROR 1045 (28000): Access denied for user === Message: ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: YES) Solution: * Check the typo of user name. * Check the typo of password. * If you are using the console command, escape the password if it contains special characters e.g. {{kbd | key=<nowiki>mysql -u root -p'PASSWORD'</nowiki>}}<ref>[http://superuser.com/questions/123928/escaping-a-password-using-mysqldump-console escape characters - Escaping a password using mysqldump console - Super User]</ref> * You may need to delete the existing account setting and re-config again. === ERROR 1827 (HY000): The password hash doesn't have the expected format. Check if the correct password algorithm is being used with the PASSWORD() function. === Wrong sql query as follows: <pre> CREATE USER 'test'@'localhost' IDENTIFIED BY PASSWORD 'my_password'; </pre> Solution: (1) Check if the account was created or not <pre> SELECT User,Host FROM mysql.user; </pre> (2a) If the account was created, set the password for the account. <pre> SET PASSWORD FOR 'test'@'localhost' = PASSWORD('my_password'); </pre> (2b) If the account was NOT created, re-create the account. <pre> CREATE USER 'test'@'localhost' IDENTIFIED BY 'my_password'; </pre> references * [http://dev.mysql.com/doc/refman/5.7/en/create-user.html MySQL :: MySQL 5.7 Reference Manual :: 14.7.1.2 CREATE USER Syntax] * [http://dev.mysql.com/doc/refman/5.7/en/set-password.html MySQL :: MySQL 5.7 Reference Manual :: 14.7.1.7 SET PASSWORD Syntax] * [http://dev.mysql.com/doc/refman/5.7/en/drop-user.html MySQL :: MySQL 5.7 Reference Manual :: 14.7.1.3 DROP USER Syntax] == SQL and Query Errors == === Caught exception: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined === Solutions * Number of question marks is not matched with the number of query values <ref>[https://stackoverflow.com/questions/10966251/sqlstatehy093-invalid-parameter-number-parameter-was-not-defined php Invalid parameter number: parameter was not defined - Stack Overflow]</ref> * The array of query values should not be the associative array. Use sequential array! === ERROR 1054 - Unknown column in 'where clause' === Message: [Err] 1054 - Unknown column 'xxx' in 'where clause' Solution: # check the column name 'xxx' if exists # if the column name 'xxx' was computed by the [http://dev.mysql.com/doc/refman/5.7/en/example-user-variables.html User-Defined Variables]. Enclosed the whole query into another parent derived query. <pre> -- The query which met the error message: [Err] 1054 - Unknown column 'rank' in 'where clause' SELECT semi.*, IF(semi.id = semi.prev, @rank := @rank +1, @rank := 1 ) AS `rank` FROM ( ... ) semi WHERE semi.rank <= 10 </pre> Enclosed the whole query into another parent derived query. <pre> SELECT final.* FROM ( SELECT semi.*, IF(semi.id = semi.prev, @rank := @rank +1, @rank := 1 ) AS `rank` FROM ( ... ) semi ) final 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> === ERROR 1052 - Column 'column_name' in field list is ambiguous === Message: Error Code: 1052. Column 'column_name' in field list is ambiguous Cause: Since 'column_name' is present in 2 or more tables ...<ref>[https://stackoverflow.com/questions/19351633/error-code-1052-column-admin-id-in-field-list-is-ambiguous mysql - Error Code: 1052 Column 'admin_id' in field list is ambiguous - Stack Overflow]</ref> Solution: Remain only one table name 'column_name' OR adding the table name alias. === Error!: SQLSTATE[42000]: Syntax error or access violation === Message: {{kbd | key=<nowiki>Error!: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ...</nowiki>}} Solution: * [[SQL syntax debug]] * [https://www.eversql.com/sql-syntax-check-validator/ SQL Syntax Check Online, SQL Validator, Instant SQL Compiler Online – EverSQL] {{exclaim}} Not support the [https://www.php.net/manual/en/pdo.prepare.php PHP: PDO::prepare] which the query syntax contains question marks. === ERROR 1366: Incorrect string value === Message: SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xF0\x9F\x87\xAF\xF0\x9F...' for column 'XXX' Solution: * Check the charset of PHP PDO. AND execute {{kbd | key=set names utf8mb4}}<ref>[https://stackoverflow.com/questions/54947392/incorrect-string-value-when-trying-to-pass-emoji-to-the-db-encoded-with-utf8mb4 php - Incorrect string value when trying to pass emoji to the db encoded with utf8mb4 - Stack Overflow]</ref> * Check the configuration of table ** CHARACTER SETS (aka 字元集、字符集): {{kbd | key=utf8mb4}} ** COLLATION (aka 定序、字元序): {{kbd | key=utf8mb4_unicode_ci}} === ERROR 1070 (42000): Specified key was too long; max key length is 767 bytes === '''Envoronment''': MySQL 5.6 '''Root cause''': "By default, the index key prefix length limit is 767 bytes. See Section 13.1.13, “CREATE INDEX Statement”. For example, you might hit this limit with a column prefix index of more than 255 characters on a TEXT or VARCHAR column, assuming a utf8mb3 character set and the maximum of 3 bytes for each character. When the innodb_large_prefix configuration option is enabled, the index key prefix length limit is raised to 3072 bytes for InnoDB tables that use the DYNAMIC or COMPRESSED row format." <ref>[https://dev.mysql.com/doc/refman/5.6/en/innodb-limits.html MySQL :: MySQL 5.6 Reference Manual :: 14.22 InnoDB Limits]</ref> '''Solution'''<ref>[https://www.opencli.com/mysql/mysql-%E5%95%8F%E9%A1%8C-1071-42000-specified-key-was-too-long MySQL 問題: 1071 (42000): Specified key was too long]</ref><ref>[https://terrytongcc.com/%E5%A6%82%E4%BD%95%E8%A7%A3%E6%B1%BAmysql%E5%87%BA%E7%8F%BEerror-1118-row-size-too-large-8126%E5%95%8F%E9%A1%8C/ 如何解決MySQL出現Error 1118: row size too large (> 8126)問題 | Terry Tong – Full Stack Web Developer]</ref>: * execute SQL query as the following: <pre> SET GLOBAL innodb_file_format = Barracuda; SET GLOBAL innodb_file_format_max = Barracuda; </pre> * modify the MySQL configuration file <pre> innodb_file_per_table = 1 innodb-file-format = BARRACUDA innodb-large-prefix = ON innodb_file_format_max = BARRACUDA </pre> * restart the MySQL server * execute SQL query as the following: <pre> ALTER TABLE `table_name` ROW_FORMAT=COMPRESSED; </pre> === ERROR 1267: Illegal mix of collations (utf8mb4_general_ci,COERCIBLE) and (latin1_swedish_ci,IMPLICIT) for operation 'concat' === Error condition: Tried to concat different type of data e.g. CONCAT(string, int) 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 == === Error: SQLSTATE[HY000] [2002] No such file or directory === Error message: SQLSTATE[HY000] [2002] No such file or directory Solutions: * Modify the host of database from {{kbd | key=localhost}} to {{kbd | key=127.0.0.1}} === ERROR 2013: Lost connection to MySQL server during query === Message: Error Code: 2013. Lost connection to MySQL server during query Condition: After executed the following query contains number of rows which exceed 1,000,000 rows, I met the error message 'Error Code: 2013. Lost connection to MySQL server during query'. <pre> INSERT IGNORE INTO `target`.`table` SELECT * FROM `source`.`table`; </pre> Solution: * Increase the settings of (1) '''DBMS connection keep-alive interval (in seconds)''' & (2) '''DBMS connection read time out (in seconds)''' on [https://www.mysql.com/products/workbench/ MySQL Workbench] <ref>[http://stackoverflow.com/questions/16877574/how-can-i-execute-sql-queries-that-take-longer-99-999-seconds-on-mysql-workbench How can I execute SQL queries that take longer 99,999 seconds on MySQL Workbench? - Stack Overflow]</ref><ref>[http://stackoverflow.com/questions/10563619/error-code-2013-lost-connection-to-mysql-server-during-query Error Code: 2013. Lost connection to MySQL server during query - Stack Overflow]</ref>. And remember to restart the MySQL Workbench after the settings were modified. e.g. The default setting of '''DBMS connection read time out (in seconds)''' is 30 seconds, you may increase to 6000 seconds (100 minutes). * Reduce the number of rows to reduce the execution time (1) by using {{kbd | key=LIMIT}} clause (2) or by splitting the query size e.g. {{kbd | key=<nowiki>MOD(column, 2) = 0</nowiki>}} & {{kbd | key=<nowiki>MOD(column, 2) > 0</nowiki>}} if the column is numeric. <pre> INSERT IGNORE INTO `target`.`table` SELECT * FROM `source`.`table` LIMIT 0, 10000; </pre> === ERROR 2003 (HY000): Can't connect to MySQL server on 'ip' === '''ERROR 2003 (HY000): Can't connect to MySQL server on 'IP' ''' Solution: * Check if the IP is alive '''ERROR 2003 (HY000): Can't connect to MySQL server on 'IP' (111 "Connection refused")''' Solution: * Check if the MySQL service is running or not<ref>[https://www.cyberciti.biz/faq/how-to-find-out-if-mysql-is-running-on-linux/ HowTo: Find out If MySQL Is Running On Linux Or Not]</ref>. If not, start the MySQL service. * Check the firewall rules '''ERROR 2003 (HY000): Can't connect to MySQL server on 'IP' (116 "Connection timed out")''' Solution: * Check the configuration of MySQL ** comment out [https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_bind-address bind-address] = 127.0.0.1 or set to * ** comment out [https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_skip-networking skip-networking] * Check the permission of MySQL database user. * Check the firewall rules at (1) your personal computer (2) the server where MySQL service located (3) ISP/VM providers. More on [https://devops.profitbricks.com/tutorials/install-mysql-on-centos-7/#firewall-rules Install MySQL on CentOS 7 | ProfitBricks DevOps Central] ** Check if your IP address was included in the allowed IP address list of firewall rules. ** Check if your IP address was changed by using [https://whatismyipaddress.com/ What Is My IP Address?] services. * (optional) Monitor the firewall activity. More on [https://www.howtogeek.com/220204/how-to-track-firewall-activity-with-the-windows-firewall-log/ How to Track Firewall Activity with the Windows Firewall Log] on {{Win}} References: * [https://support.rackspace.com/how-to/mysql-connect-to-your-database-remotely/ Connect to a MySQL database remotely] * [http://wiki.navicat.com/wiki/index.php/Error_2003 Error 2003 - Navicat Wiki] * [http://faq.webyog.com/content/23/15/en/error-no-2003-can_t-connect.html SQLyog MySQL Admin FAQ - Error no. 2003: Can't connect...] === ERROR 2002: SQLSTATE[HY000] [2002] Only one usage of each socket address (protocol/network address/port) is normally permitted === Message: (1) [2002] Only one usage of each socket address (protocol/network address/port) is normally permitted (2) "SQLSTATE[HY000] [2002] 一次只能用一個通訊端位址 (通訊協定/網路位址/連接埠)。" in Chinese Solution: [https://stackoverflow.com/questions/10317974/mysql-php-error2002-only-one-usage-of-each-socket-address-protocol-network-a MySQL/PHP Error:(2002) Only one usage of each socket address (protocol/network address/port) is normally permitted - Stack Overflow] === ERROR 2002: Cannot connect: SQLSTATE[HY000] [2002] === Condition on Cygwin terminal of Windows: <pre> $ mysql -u root -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2) $ mysql -h localhost -u root -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2) </pre> Solution: * Change {{kbd | key=<nowiki>-h localhost</nowiki>}} to {{kbd | key=<nowiki>-h 127.0.0.1</nowiki>}} <pre> $ mysql -h 127.0.0.1 -u root -p </pre> * 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. === 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 == === could not access the mysql log === Version: XAMPP 5.6.15-1 on {{Mac}} Cause: * the error log only be accessed by the user named {{kbd | key=mysql}}<ref>Open the MySQL configuration file located: /Applications/XAMPP/xamppfiles/etc/my.cnf <pre> # The MySQL server [mysqld] user = mysql </pre></ref> Solution <ref>[http://computerplumber.com/2009/01/using-the-chmod-command-effectively/ Using the CHMOD command effectively @ Computer Plumber]</ref>: <pre> find the path to the mysql log $ ls /Applications/XAMPP/xamppfiles/var/mysql/*.local.err find the file name of mysql log ex: XXXMacBook-Pro.local.err set the permission of log $ sudo chmod 774 /Applications/XAMPP/xamppfiles/var/mysql/XXXMacBook-Pro.local.err </pre> === Could not open single-table tablespace file filename.ibd === Version: XAMPP 5.6.15-1 on {{Mac}} Condition: The Mac was shutdown accidentally and the database was not shutdown normally. After reboot the Mac, unable to start the MySQL service<ref>[http://stackoverflow.com/questions/35184367/error-could-not-open-single-table-tablespace-file-scrapers-records-ibd mysql - Error: could not open single-table tablespace file .\scrapers\records.ibd - Stack Overflow]</ref><ref>[http://chepri.com/our-blog/mysql-innodb-corruption-and-recovery/ MySQL Won't Start - InnoDB Corruption and Recovery. - Chepri]</ref>. Possible solution: # Edit the MySQL configuration file located: /Applications/XAMPP/xamppfiles/etc/my.cnf # Add this line: {{kbd | key=<nowiki>innodb_force_recovery = 1</nowiki>}} # Try to start the MySQL service # If the MySQL service started successfully, edit the MySQL configuration file and mark this line : {{kbd | key=<nowiki>#innodb_force_recovery = 1</nowiki>}} # Restart the MySQL service === MySQL server has gone away === 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>. * Example error log located at {{kbd | key = <nowiki>file_name_of_error_log</nowiki>}} are as following: <pre> 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> 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>. === Error!: SQLSTATE[HY000]: General error === Message: Error!: SQLSTATE[HY000]: General error Condition: When I used the [http://php.net/manual/en/book.pdo.php PHP: PDO] Solutions: * "You do not use {{kbd | key=<nowiki>$result = $stmt->fetchAll();</nowiki>}} with update or insert queries" <ref>[https://stackoverflow.com/questions/12979510/pdo-error-sqlstatehy000-general-error-when-updating-database php - PDO error: " SQLSTATE[HY000]: General error " When updating database - Stack Overflow]</ref>. * You do not use {{kbd | key=<nowiki>$result = $stmt->fetchAll();</nowiki>}} in the query {{kbd | key=<nowiki>INTO OUTFILE ...</nowiki>}} <ref>[http://www.tech-recipes.com/rx/1475/save-mysql-query-results-into-a-text-or-csv-file/ Save MySQL query results into a text or CSV file]</ref><ref>[https://stackoverflow.com/questions/13369164/cant-create-write-to-file-errcode-22 mysql - Can't create/write to file (Errcode: 22) - Stack Overflow]</ref>. === Error!: SQLSTATE[HY000]: General error: 3 Error writing file xxx.tmp (Errcode: 28 - No space left on device) === Example error message: Error!: SQLSTATE[HY000]: General error: 3 Error writing file 'C:\Windows\SERVIC~2\NETWOR~1\AppData\Local\Temp\MY2713.tmp' (Errcode: 28 - No space left on device) Condition: Check the disk free space of mysql {{kbd | key=tmpdir}} folder Solutions: Increase the free space of mysql {{kbd | key=tmpdir}} folder. Or change the mysql {{kbd | key=tmpdir}} folder with another hard disk drive contains more free space<ref>[https://stackoverflow.com/questions/11990887/changing-the-tmp-folder-of-mysql Changing the tmp folder of mysql - Stack Overflow]</ref>. * Check the current mysql {{kbd | key=tmpdir}} folder. Query the syntax {{kbd | key=<nowiki>SHOW VARIABLES LIKE 'tmpdir';</nowiki>}}. ** On {{Win}} the default temporary folder<ref>[https://answers.microsoft.com/en-us/windows/forum/windows_7-windows_programs/where-is-the-temporary-folder/44a039a5-45ba-48dd-84db-fd700e54fd56 Where is the Temporary folder? - Microsoft Community]</ref> is {{kbd | key=<nowiki>%TMP%</nowiki>}} = {{kbd | key=<nowiki>%USERPROFILE%\AppData\Local\Temp</nowiki>}}. ** On {{Linux}} the default temporary folder maybe is {{kbd | key=<nowiki>/tmp</nowiki>}} * Edit the [https://dev.mysql.com/doc/refman/5.7/en/option-files.html mysql configuration file] <pre> [mysqld] tmpdir=X:/temp </pre> * Restart the MySQL service Validation * Query the syntax {{kbd | key=<nowiki>SHOW VARIABLES LIKE 'tmpdir';</nowiki>}} to validate the modification of mysql configuration file. === errno 41 - Error dropping database === Message: '''Error dropping database (can't rmdir '.\TABLE_NAME', errno: 41)''' occurred when I executed '''DROP DATABASE `TABLE_NAME`'''; Solution: [https://stackoverflow.com/questions/17947255/error-in-dropping-a-database-in-mysql-cant-rmdir-oro-errno-41/19888293 phpmyadmin - Error in dropping a database in MySQL (can't rmdir '.\oro', errno: 41) - Stack Overflow] === How to resolve "zsh: operation not permitted: xxx.sql" === Error condition <pre> /applications/MAMP/library/bin/mysql -u [USERNAME] -p [DATABASE_NAME] < [PATH_TO_SQL_FILE] zsh: operation not permitted: PATH_TO_SQL_FILE.sql </pre> Solution: Check Security & Privacy Settings: macOS may block certain actions from the terminal due to security settings. You can try allowing full disk access to the terminal: * Open System Preferences. * Go to Security & Privacy. * Select the Privacy tab. * Scroll down to Full Disk Access. * Click the lock icon to make changes (you might need your administrator password). * Find the Terminal app or iTerm2 or whatever terminal you are using and check the box to allow full disk access. * Restart your terminal. === Resolve insufficient hard disk space where mysql data located === [http://errerrors.blogspot.com/2016/07/mysql.html Err: 解決 MySQL 資料庫所在硬碟空間不足的狀況] === PHP Fatal Error: Allowed Memory Size Exhausted when import SQL.GZ file using adminer === 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 == === ERROR: ASCII \0 appeared in the statement, but this is not allowed unless option --binary-mode is enabled and mysql is run in non-interactive mode === Message: {{kbd | key=<nowiki>ERROR: ASCII '\0' appeared in the statement, but this is not allowed unless option --binary-mode is enabled and mysql is run in non-interactive mode. Set --binary-mode to 1 if ASCII '\0' is expected. Query: ''.</nowiki>}} Condition: When I import the sql file and I met the above error message. Solution: Unzip the file and then import the file again <ref>[https://stackoverflow.com/questions/17158367/enable-binary-mode-while-restoring-a-database-from-an-sql-dump mysql - Enable binary mode while restoring a Database from an SQL dump - Stack Overflow]</ref>. The sql file is a compressed file. You may use [https://en.wikipedia.org/wiki/File_(command) file (command)] for recognizing the type of file. <pre> $ file compressed.sql compressed.sql: gzip compressed data $ file plain_text.sql plain_text.sql: UTF-8 Unicode text, with very long lines </pre> === Errcode: 13 Permission denied === The message occurred after executed {{kbd | key=<nowiki>mysqld.exe --datadir=..\data --console</nowiki>}} when I tried to start the service. (Version of MySQL:5.5.5-10.0.12-MariaDB on {{Win}}) <pre> > mysqld.exe --datadir=..\data --console 180430 10:33:38 [ERROR] mysqld.exe: File 'C:\MariaDB_10.0\bin\..\data\aria_log_control' not found (Errcode: 13 "Permission denied") 180430 10:33:38 [ERROR] mysqld.exe: Got error 'Can't open file' when trying to use aria control file 'C:\MariaDB_10.0\bin\..\data\aria_log_control' 180430 10:33:38 [ERROR] Plugin 'Aria' init function returned error. 180430 10:33:38 [ERROR] Plugin 'Aria' registration as a STORAGE ENGINE failed. 180430 10:33:38 [Note] InnoDB: Using mutexes to ref count buffer pool pages 180430 10:33:38 [Note] InnoDB: The InnoDB memory heap is disabled 180430 10:33:38 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions 180430 10:33:38 [Note] InnoDB: Compressed tables use zlib 1.2.3 180430 10:33:38 [Note] InnoDB: Not using CPU crc32 instructions 180430 10:33:38 [Note] InnoDB: Initializing buffer pool, size = 4.0G 180430 10:33:38 [Note] InnoDB: Completed initialization of buffer pool 180430 10:33:38 [ERROR] InnoDB: .\ibdata1 can't be opened in read-write mode 180430 10:33:38 [ERROR] InnoDB: The system tablespace must be writable! 180430 10:33:38 [ERROR] Plugin 'InnoDB' init function returned error. 180430 10:33:38 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. 180430 10:33:38 [Note] Plugin 'FEEDBACK' is disabled. 180430 10:33:38 [ERROR] Unknown/unsupported storage engine: innodb 180430 10:33:38 [ERROR] Aborting 180430 10:33:38 [Note] mysqld.exe: Shutdown complete </pre> Solutions: Open the command line with administrative privileges. (How to: [https://www.howtogeek.com/194041/how-to-open-the-command-prompt-as-administrator-in-windows-8.1/ How to Open the Command Prompt as Administrator in Windows 8 or 10]) === Navicat error: Import data mismatch === Error: When importing an Excel file into a MySQL database using Navicat, there is an issue with the total number of records not matching. Solution: Delete blank rows and check for any duplicate primary key data. Solution: * [https://errerrors.blogspot.com/2023/11/blog-post.html 解決 NaviCat 匯入 Excel 檔案到資料庫,出現資料總筆數不一致的問題] (written in Mandarin) === Navicat error: [Exp] OLE error 800A03EC === error message: <pre> [Msg] [Exp] Export to - test.xlsx [Err] [Row1048576] [Exp] OLE error 800A03EC [Err] [Row1048577] [Exp] OLE error 800A03EC [Err] [Row1048578] [Exp] OLE error 800A03EC [Err] [Row1048579] [Exp] OLE error 800A03EC </pre> cause: * Rows count of results exceed the limit of [[Microsoft Excel]] Worksheet size: 1,048,576 rows solution: * 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/> {{Template:Data factory flow}} [[Category: MySQL]] [[Category: Database]] [[Category: Data Science]] [[Category: Revised with LLMs]]
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Data factory flow
(
edit
)
Template:Exclaim
(
edit
)
Template:Kbd
(
edit
)
Template:LanguageSwitcher
(
edit
)
Template:Linux
(
edit
)
Template:Mac
(
edit
)
Template:Win
(
edit
)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information