简体   繁体   English

用点创建mysql数据库

[英]mysql Database creation with dot

I want to create a database using following syntax 我想使用以下语法创建数据库

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

but whenever I try to use dot (.) in database name, it giving me error. 但是每当我尝试在数据库名称中使用点(。)时,都会出现错误。

[root@aee9a1889c3f 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

[root@aee9a1889c3f wpg.master]#

[root@aee9a1889c3f wpg.master]#

[root@aee9a1889c3f 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

I know I can do that using sql editor like SQL pro or using mysql command editor, but I want to do that this way. 我知道我可以使用像SQL pro这样的sql编辑器或使用mysql命令编辑器来做到这一点,但是我想这样做。 Please help. 请帮忙。

Thanks in advance 提前致谢

If you use the mysqladmin utility it can be done: 如果使用mysqladmin实用程序,则可以完成以下操作:

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

If you want to do it using mysql client you need to use single quotes (to avoid shell expansion of the backticks (`) 如果要使用mysql客户端执行此操作,则需要使用单引号(以避免反引号(`)的shell扩展。

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

You cannot have a dot in a database name. 数据库名称中不能包含点。

The following documentation lists the permitted characters: https://dev.mysql.com/doc/refman/5.7/en/identifiers.html 以下文档列出了允许的字符: https : //dev.mysql.com/doc/refman/5.7/en/identifiers.html

From the documentation: 从文档中:

"database, ... are known as identifiers" “数据库,...被称为标识符”


Permitted characters in unquoted identifiers: 未加引号的标识符中允许的字符:

  • ASCII: [0-9,az,AZ$_] (basic Latin letters, digits 0-9, dollar, underscore) ASCII:[0-9,az,AZ $ _](基本拉丁字母,数字0-9,美元,下划线)
  • Extended: U+0080 .. U+FFFF 扩展:U + 0080 .. U + FFFF

Permitted characters in quoted identifiers include the full Unicode Basic Multilingual Plane (BMP), except U+0000: 带引号的标识符中允许的字符包括完整的Unicode基本多语言平面(BMP),但U + 0000除外:

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

Update: 更新:

As mentioned in the documentation, it is possible with backquotes: 如文档中所述,可以使用反引号:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM