Editing
排除 MySQL 技術疑難問題
(section)
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!
== 資料庫和表操作錯誤 == === 無法開啟單表表空間檔案 filename.ibd === 版本:XAMPP 5.6.15-1,運行於{{Mac}} 狀況:Mac 意外關機,且資料庫沒有正常關閉。重啟 Mac 後,無法啟動 MySQL 服務<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>。 可能的解決方案: # 編輯位於:/Applications/XAMPP/xamppfiles/etc/my.cnf 的 MySQL 設定檔 # 增加此行:{{kbd | key=<nowiki>innodb_force_recovery = 1</nowiki>}} # 嘗試啟動 MySQL 服務 # 如果 MySQL 服務成功啟動,編輯 MySQL 設定檔並註釋掉這行:{{kbd | key=<nowiki>#innodb_force_recovery = 1</nowiki>}} # 重啟 MySQL 服務 === errno 41 - 刪除資料庫時出錯 === 訊息:執行 '''DROP DATABASE `TABLE_NAME`''' 時出現 '''錯誤刪除資料庫(無法刪除目錄 '.\TABLE_NAME',errno: 41)'''; 解決方案:[https://stackoverflow.com/questions/17947255/error-in-dropping-a-database-in-mysql-cant-rmdir-oro-errno-41/19888293 phpmyadmin - 刪除 MySQL 中的資料庫時出錯(無法刪除目錄 '.\oro',errno: 41)- Stack Overflow] === ERROR 1005 (HY000) at line xx: 無法創建表 'TABLE_NAME' (errno: 28) === 解決方案 * 檢查 mysql 數據文件夾所在的磁碟空間是否足夠。例如,在 {{Linux}} 上輸入 {{kbd | key=df -h}} * 更多資訊請見 [http://stackoverflow.com/questions/11045279/error-1005-hy000-cant-create-table-errno-150 mysql - ERROR 1005 (HY000): 無法創建表 (errno: 150) - Stack Overflow]。 === ERROR 1006 (HY000): 無法創建資料庫 'DATABASE_NAME' (errno: 28) === 解決方案 * 檢查 mysql 數據文件夾所在的磁碟空間是否足夠。例如,在 {{Linux}} 上輸入 {{kbd | key=df -h}} * 更多資訊請見 [http://stackoverflow.com/questions/18719748/error-1006-hy000-cant-create-database-errno-13-mysql-5-6-12 ERROR 1006 (HY000) 無法創建資料庫 (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> 解決方式 * 手動刪除資料庫目錄中殘留的非 MySQL 檔案(例如 .sql 檔案),再重新執行 DROP DATABASE;或直接手動刪除整個資料夾。 根本原因 * MySQL 的 DROP DATABASE 只會移除它所管理的檔案。資料目錄中若存在其他外來檔案(例如 .sql 備份檔),將導致 rmdir 無法移除資料夾,進而觸發 errno 17(ENOTEMPTY)。 === ERROR 1017 - Can't find file: '.\DATABASE\TABLE.frm' (errno: 22 - Invalid argument) === 訊息: [Err] 1017 - Can't find file: '.\DATABASE\TABLE.frm' (errno: 22 - Invalid argument) 解決方案: * 檢查 DATABASE\TABLE.frm 文件是否存在。如果不存在,可能需要在執行 MySQL 查詢前先創建該表。 * 檢查 DATABASE\TABLE.frm 文件或所在文件夾的權限<ref>[http://stackoverflow.com/questions/12106727/mysql-copying-tables-files-gives-rise-to-error-1017-hy000-cant-find-file MySQL,複製表文件出現 “ERROR 1017 (HY000): Can't find file:” 即使它在那裡 - Stack Overflow]</ref><ref>[https://www.percona.com/forums/questions-discussions/mysql-and-percona-server/2762-error-1017-hy000-can-t-find-file 錯誤 1017 (HY000): 找不到文件 - Percona 社區]</ref>。''未經驗證'' === ERROR 1052 - Column 'column_name' in field list is ambiguous === 訊息:Error Code: 1052. Column 'column_name' in field list is ambiguous 欄位列表中的 'column_name' 模糊不清 原因:由於 'column_name' 出現在兩個或多個表中...<ref>[https://stackoverflow.com/questions/19351633/error-code-1052-column-admin-id-in-field-list-is-ambiguous mysql - 錯誤代碼:1052 欄位列表中的 'admin_id' 模糊不清 - Stack Overflow]</ref> 解決方案:只保留一個表名 'column_name' 或添加表名別名。 === 錯誤 1054 - 'where 子句' 中未知的欄位 === 訊息:[Err] 1054 - 'where 子句' 中未知的欄位 'xxx' 解決方案: # 檢查 'xxx' 欄位名稱是否存在 # 如果 'xxx' 欄位名稱是由 [http://dev.mysql.com/doc/refman/5.7/en/example-user-variables.html 使用者定義的變數] 計算得出。將整個查詢放入另一個母查詢中。 <pre> -- 遇到錯誤訊息的查詢:[Err] 1054 - 'where 子句' 中未知的欄位 'rank' SELECT semi.*, IF(semi.id = semi.prev, @rank := @rank +1, @rank := 1 ) AS `rank` FROM ( ... ) semi WHERE semi.rank <= 10 </pre> 將整個查詢放入另一個母查詢中。 <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> === 錯誤 1114 (HY000): 表格 `TABLE_NAME` 已滿 === 可能的解決方案 * 因為 [https://dev.mysql.com/doc/refman/5.7/en/data-directory.html MySQL 數據目錄] 所在的硬碟分區已滿或幾乎已滿,釋放一些硬碟空間<ref>[http://stackoverflow.com/questions/730579/error-1114-hy000-the-table-is-full mysql - 錯誤 1114 (HY000): 表格已滿 - Stack Overflow]</ref>。 === 錯誤 1170: 在鍵規格中使用 BLOB/TEXT 欄位且沒有鍵長 === 情況 * 嘗試建立新表格時的 SQL 語法 <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> 解決方案:在鍵規格中使用 BLOB/TEXT 欄位並指定鍵長,例如 {{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> === 錯誤 1813: 表格 xxx 的表空間已存在 === 訊息:錯誤 1813 表格 xxx 的表空間已存在。 解決方案 * [https://stackoverflow.com/questions/15694168/error-tablespace-for-table-xxx-exists-please-discard-the-tablespace-before-imp mysql - 錯誤:表格 xxx 的表空間已存在。請在導入前丟棄表空間 - Stack Overflow] === 錯誤 1049 (42000): 未知的資料庫 === 訊息:錯誤 1049 (42000): 未知的資料庫 'MY_DATABASE_p' 解決方案: * 檢查 'MY_DATABASE_p' 資料庫是否存在 * 如果您在使用控制台時希望連接到 'MY_DATABASE' 資料庫,請檢查資料庫名稱後是否沒有 {{kbd | key=TAB}} 字元。 === 錯誤 1070 (42000): 指定的鍵太長;最大鍵長為 767 位元組 === '''環境''': MySQL 5.6 '''根本原因''': "預設情況下,索引鍵前綴長度限制為 767 位元組。參見第 13.1.13 節,“CREATE INDEX 語句”。例如,在 TEXT 或 VARCHAR 列上,如果使用 utf8mb3 字元集,並且每個字元最多 3 位元組,您可能會在列前綴索引超過 255 個字元時達到此限制。當啟用 innodb_large_prefix 配置選項時,對於使用 DYNAMIC 或 COMPRESSED 行格式的 InnoDB 表,索引鍵前綴長度限制提高到 3072 位元組。" <ref>[https://dev.mysql.com/doc/refman/5.6/en/innodb-limits.html MySQL :: MySQL 5.6 參考手冊 :: 14.22 InnoDB 限制]</ref> '''解決方案'''<ref>[https://www.opencli.com/mysql/mysql-%E5%95%8F%E9%A1%8C-1071-42000-specified-key-was-too-long MySQL 問題: 1071 (42000): 指定的鍵太長]</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 – 全棧 Web 開發人員]</ref>: * 執行以下 SQL 查詢: <pre> SET GLOBAL innodb_file_format = Barracuda; SET GLOBAL innodb_file_format_max = Barracuda; </pre> * 修改 MySQL 配置文件 <pre> innodb_file_per_table = 1 innodb-file-format = BARRACUDA innodb-large-prefix = ON innodb_file_format_max = BARRACUDA </pre> * 重啟 MySQL 伺服器 * 執行以下 SQL 查詢: <pre> ALTER TABLE `table_name` ROW_FORMAT=COMPRESSED; </pre>
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)
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