2

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. Please help.

Thanks in advance

2 Answers 2

6

If you use the mysqladmin utility it can be done:

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 -u<uname> -p<password> 'create database `a.n`'
2
  • 1
    yup that , I was looking for. Thanks
    – user6457056
    Mar 13, 2017 at 16:29
  • I just edited my answer to show how to do it with mysql instead of mysqladmin Mar 13, 2017 at 16:30
0

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

From the documentation:

"database, ... are known as identifiers"


Permitted characters in unquoted identifiers:

  • ASCII: [0-9,a-z,A-Z$_] (basic Latin letters, digits 0-9, dollar, underscore)
  • Extended: U+0080 .. U+FFFF

Permitted characters in quoted identifiers include the full Unicode Basic Multilingual Plane (BMP), except U+0000:

  • ASCII: U+0001 .. U+007F
  • Extended: 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)
3
  • ASCII: U+0001 .. U+007F does include the . symbol (U+002E). So it can be used in quoted identifiers Mar 13, 2017 at 16:24
  • yes, we can have try to do from mysql command editor "create database a.b";
    – user6457056
    Mar 13, 2017 at 16:26
  • @user6457056 I updated the answer to show a solution with backquotes
    – Gab
    Mar 13, 2017 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.