create a database

dotKer

Member
Joined
Aug 16, 2019
Messages
69
Reaction score
14
Credits
0
(1) I installed xubuntu.
(2) I installed Apache.
(3) I installed PHP
(4) I installed mySQL

The php version is 7.2. and the below shows the version of the Apache and mySQl.
dotker@dotker:/$ apachectl -v
Server version: Apache/2.4.29 (Ubuntu)
Server built: 2019-08-26T13:41:23
dotker@dotker:/$ mysql --version
mysql Ver 14.14 Distrib 5.7.27, for Linux (i686) using EditLine wrapper
I am going to mysql with the code below.
dotker@dotker:/$ mysql -u root --password
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \\g.
Your MySQL connection id is 13
Server version: 5.7.27-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.
And I am checking whether the mysql work correctly or not with the below.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
So far, so good.
Now I like to create a test database for testing.
mysql> CREATE DATABASE 'testDB';
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 ''testDB'' at line 1
mysql> CREATE DATABASE 'testDB' DEFAULT CHARACTER SET utf8 COLLATE utf8__general_ci;
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 ''testDB' DEFAULT CHARACTER SET utf8 COLLATE utf8__general_ci' at line 1
The quote above shows It doesn't create the database "testDB".

What's wrong with it?

Can I make a new database with your help?

Why doesn't it work?

Where is the manual for this?
 


Last edited:
why?
you don't need to add single quote ' on your database name
 
there is another approach phpMyadmin a gui , there you can ctreate database, add table, etc set permissions
 
why?
you don't need to add single quote ' on your database name

In MySQL the proper way for quoting elements name is the backquote ``.
So you can do
Code:
CREATE DATABASE `testDB`;

If you use the single quote ' it will be considered as a string token, which is only allowed where a string is required (when inserting a string in a table for example).
Why is it like this ? Because it's the way the language was designed. It was probably easier to build a parser with identifier tokens being explicitly different from string tokens than having to check what is the role of the string depending on context.
 
So let me just clarify this for the benefit of The Viewers, and for people whose first language is not English:

'testDB'

... is wrong

and

`testDB`

... is right.

Is that so, Julien?

Wiz

BTW for users of US keyboard and some others, the back quote is on the same key as the tilde

~

... upper left.
 

Members online


Top