php" type="hidden"/>

[Err] 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 ''

php


[Err] 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 ''<h1 style="text-align: center;">php實現 字符串分割</h' at line 1

一、總結

一句話總結:我本來都是直接打開sql復制里面的內容到mysql中執行,這次是用nodepad++,所以出錯。這不是錯誤,1064是語法錯誤。

 

 

 

二、[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL s

[Err] 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 at line 3

MySQL 5.6,Navicat For MySQL 10.0.10 中執行SQL語句時提示此錯誤,在CMD中執行SQL文件中的語句時提示以下錯誤:

1 D:\Users\Aven>mysql -uroot -p < F:\Publish\Data\share_update.sql
2 Warning: Using a password on the command line interface can be insecure.
3 ERROR 1064 (42000) at line 4: You have an error in your SQL syntax; check the ma
4 nual that corresponds to your MySQL server version for the right syntax to use n
5 ear 'ALTER聽TABLE聽mcu聽CHANGE聽`LOCAL_ID`聽`LOCAL_ID`聽VARCHAR(50)聽'
6 at line 1

 

解決方案:

發現解決該問題的關鍵,是錯誤提示中的空格都是“聽”,這讓我想到是文件的編碼問題,然后做文件編碼的轉換。 
推薦使用Notepad++,編碼轉換非常方便,如圖: 

 


轉換為UTF-8格式,問題依舊,再轉為ANSI格式試試: 

 

 

哈哈,原形畢露了吧!把?都替換為空格,保存,再執行,一切OK了。

反思:

為什么會出現這種問題呢? 
這些語句是從QQ復制到Word中,又從Word中復制到Notepad++中, 
估計是從QQ或Word中復制出來的空格有問題。

 

三、完美解決 ERROR 1064 (42000): You have an error in your SQL syntax ... near …

在MySQL命令行使用sql語句進行建表時,MySQL 報錯,這個問題之前遇到過幾次,但是總是會因為疏忽又相遇,今天把這個問題寫出來,加深印象吧。

sql語句:

CREATE TABLE 'lrs_audit_rule_package'( 'id' BIGINT(20) AUTO_INCREMENT PRIMARY KEY COMMENT '主鍵', 'package_code' varchar(6) NOT NULL COMMENT '規則包', 'package_type' varchar(2) NOT NULL COMMENT '規則包類型', 'package_desc' varchar(100) COMMENT '描述', 'create_time' datetime DEFAULT NULL COMMENT '創始時間', 'modified_time' datetime DEFAULT NULL COMMENT '修改時間' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='審核規則包';

看上去這條sql語句確實沒毛病,但是運行起來就是報錯
報錯信息:

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 ''lrs_audit_rule_package'(
  'id' BIGINT(20) AUTO_INCREMENT PRIMARY KEY COMMENT ' at line 1

其實這個問題就是語法上的錯誤,在MySQL中,為了區分MySQL的關鍵字與普通字符,MySQL引入了一個反引號。
詳情見:https://dev.mysql.com/doc/refman/5.5/en/keywords.html

在上述的sql語句中,列名稱使用的是單引號而不是反引號,所以會就報了這個錯誤出來。修改后

CREATE TABLE `lrs_audit_rule_package`( `id` BIGINT(20) AUTO_INCREMENT PRIMARY KEY COMMENT '主鍵', `package_code` varchar(6) NOT NULL COMMENT '規則包', `package_type` varchar(2) NOT NULL COMMENT '規則包類型', `package_desc` varchar(100) COMMENT '描述', `create_time` datetime DEFAULT NULL COMMENT '創始時間', `modified_time` datetime DEFAULT NULL COMMENT '修改時間' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='審核規則包';

再次運行就不會報錯了,但是有一點需要注意,后面列的注釋不能用反引號,因為這只是一個普通字符串,不是MySQL的關鍵字。

在英文鍵盤輸入環境下,按圖示按鈕輸入反引號 `

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 解決:[Err] 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 ERROR 1064 (42000): 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 MySql 執行語句錯誤 Err] 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 ERROR 1064 (42000): 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 '11. set password for 'root'@'localhost' 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 '"id", Mysql語法錯誤之> 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' 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 'groups)VALUES('1','hh','hh@163.com','Boss')' at line 1 Django進行數據遷移時,報錯:(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 '(6) NOT NULL)' at line 1") SQL語句報錯:You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 報錯--->java.sql.SQLSyntaxErrorException: 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 'delect from testd
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM