我遇到了一些有点奇怪的事情。我正在从Windows上的文件名运行我的查询
与source c:\sql\general.sql
类似,但失败
mysql> source c:\sql\general.sql
--------------
mysql Ver 14.14 Distrib 5.6.11, for Win32 (x86)
Connection id: 6
Current database: joins
Current user: root@localhost
SSL: Not in use
Using delimiter: ;
Server version: 5.6.11 MySQL Community Server (GPL)
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: utf8
Db characterset: utf8
Client characterset: cp850
Conn. characterset: cp850
TCP port: 3306
Uptime: 5 days 2 hours 53 min 45 sec
Threads: 1 Questions: 167 Slow queries: 0 Opens: 86 Flush tables: 1 Open ta
bles: 62 Queries per second avg: 0.000
--------------
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 'sourc
e c:ql' at line 1
->
此查询
CREATE TABLE mytable (
id INT NOT NULL AUTO_INCREMENT,
name varchar(50) NOT NULL,
PRIMARY KEY (id)
);
但是,当我尝试运行相同的查询但这次命名我的文件stuff.sql
mysql> source c:\sql\stuff.sql
Query OK, 0 rows affected (0.65 sec)
这是一个常见错误吗?
更新
source c:\sql\\general.sql
产生此错误
mysql> source c:\sql\\general.sql
--------------
mysql Ver 14.14 Distrib 5.6.11, for Win32 (x86)
Connection id: 6
Current database: joins
Current user: root@localhost
SSL: Not in use
Using delimiter: ;
Server version: 5.6.11 MySQL Community Server (GPL)
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: utf8
Db characterset: utf8
Client characterset: cp850
Conn. characterset: cp850
TCP port: 3306
Uptime: 5 days 3 hours 42 min 4 sec
Threads: 1 Questions: 192 Slow queries: 0 Opens: 97 Flush tables: 1 Open ta
bles: 62 Queries per second avg: 0.000
--------------
ERROR:
Unknown command '\\'.
-> ;
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 'sourc
e c:ql\\general.sql' at line 1
mysql>
答案 0 :(得分:3)
使用正斜杠:
mysql> source c:/sql/general.sql
我永远不会原谅Microsoft使用元字符作为默认目录分隔符。
答案 1 :(得分:1)
\g
在MYSQL中用作输出格式字符。你需要双重逃避,例如
source c:\sql\\general.sql