1. 程式人生 > >mysql8基礎 create database 建立的資料庫的名字是 關鍵字、特殊字元,用反引號

mysql8基礎 create database 建立的資料庫的名字是 關鍵字、特殊字元,用反引號

資料,資料,命根就在資料 ! 操作資料庫時,一定要謹慎小心。師萬物 這裡的程式碼看看就好,要有自己的判斷。遇到抉擇,要不恥上下問。

example - 錯誤的

stu@Ubuntu:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.12 MySQL Community Server - GPL

Copyright (c) 2000, 2018, 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. mysql> create database database; 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 'database' at line 1 mysql> create database @#$%%^&*; -> ; 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 '@' at line 1 mysql> exit Bye stu@Ubuntu:~$

example - 正確的

stu@Ubuntu:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.12 MySQL Community Server - GPL

Copyright (c) 2000, 2018, 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.

mysql> create database `database`;
Query OK, 1 row affected (0.09 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| database           |
| employees          |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
6 rows in set (0.01 sec)

mysql> create database `@#$%^%`;
Query OK, 1 row affected (0.03 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| @#$%^%             |
| database           |
| employees          |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
7 rows in set (0.00 sec)

mysql> exit
Bye
stu@Ubuntu:~$ 

more knowledge

  • 命名一定要規範,見名知意。
  • 一個故事:在工作中,將要見到前輩的資料庫查詢程式碼時,師萬物 很激動的,滿心歡喜。當見到了由拼音組成的表名時,瞬間冷卻了。
  • 使用反引號創建出來的特殊名字資料庫,知道有這會事就好。在實際開發中,好好寫命名與註釋,利人利己。

resource

MySQL是一個關係型資料庫管理系統,目前是開源的(2018-10)。 許可權明確,恰當選擇引擎與字符集,命名簡潔明瞭與規範。 MariaDB,Redis,MongoDB,PostgreSQL,Hive,HBase等,可以簡單地瞭解。 Workbench,phpMyAdmin,Navicat等圖形化管理工具,可以試用一下。