2017-03-13 40 views
2

我想創建一個數據庫使用以下語法MySQL數據庫的創建與點

mysql -u<uname> -p<password> -e "create database <name>" 

但每當我嘗試使用點(。)在數據庫的名字,它給我的錯誤。

[[email protected] wpg.master]# mysql -uroot -proot -e "create database 'a.n'" 
Warning: Using a password on the command line interface can be insecure. 
ERROR 1064 (42000) at line 1: 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 ''a.n'' at line 1 

[[email protected] wpg.master]# 

[[email protected] wpg.master]# 

[[email protected] wpg.master]# mysql -uroot -proot -e "create database `a.n`" 
bash: a.n: command not found 
Warning: Using a password on the command line interface can be insecure. 
ERROR 1064 (42000) at line 1: 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 1 

我知道我能做到這一點使用諸如SQL Pro或使用mysql命令編輯器SQL編輯器,但我想這樣做這種方式。請幫忙。

在此先感謝

回答

4

如果使用mysqladmin工具是可以做到的:

mysqladmin -u<uname> -p<password> create a.n 

如果你想用mysql客戶端來做,你需要使用單引號(以避免反引號的外殼擴展(`)

mysql -u<uname> -p<password> 'create database `a.n`' 
+1

的解決方案,我一直在尋找。謝謝 – user6457056

+0

我剛剛編輯我的答案,以顯示如何使用'mysql'而不是'mysqladmin' – Aegis

0

數據庫名稱中不能有點。

以下文檔列出了允許使用的字符:https://dev.mysql.com/doc/refman/5.7/en/identifiers.html

從文檔:

「數據庫,......被稱爲標識符」


在不帶引號允許的字符標識符:

  • ASCII:0-9,AZ,AZ $ _](基本拉丁字母,數字0-9美元,下劃線)
  • 擴展:U + 0080 ... U + FFFF

在加引號的標識符允許的字符有完整的Unicode基本多文種平面(BMP),除了U + 0000:

  • ASCII:U + 0001 ... U + 007F
  • 擴展:U + 0080 ... U + FFFF

更新:

如文檔中所提到的,可能與反引號:

create database `a.b`; 
Query OK, 1 row affected (0.01 sec) 
+0

ASCII:U + 0001 .. U + 007F確實包含'.'符號(U + 002E)。所以它可以用在帶引號的標識符中 – Aegis

+0

是的,我們可以試着從mysql命令編輯器做到 「create database'a.b'」; – user6457056

+0

@ user6457056我更新了答案,以顯示帶有反引號 – Gab