mysql8基础 create database 创建的数据库的名字是 关键字、特殊字符,用反引号

  •        OS : Ubuntu 18.04.1 LTS
  •        DBMS : mysql 8.0.12
  •        blog : blog.csdn.net/shiwanwu
  •  typesetting : Markdown

数据,数据,命根就在数据 ! 操作数据库时,一定要谨慎小心。师万物 的代码看看就好,要有自己的判断。遇到抉择,要不耻上下问。

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

  • [手册] dev.mysql.com/doc
  • [源码] downloads.mysql.com/archives/community
  • [Bug ] bugs.mysql.com
  • [ 测试数据 ] github.com/datacharmer/test_db
  • [规范 - 参考] yq.aliyun.com/articles/69327
  • [排名 - 参考] db-engines.com/en
  • [平台] www.csdn.net


MySQL是关系型数据库管理系统,目前是开源的(2019-02)。
明确权限,恰当地选择引擎与字符集等,规范命名。
MariaDB,Redis,MongoDB,PostgreSQL,Hive,HBase等,多作了解,拓宽心量。
Workbench,phpMyAdmin,Navicat等图形化管理工具,豫兮若冬涉川。

你可能感兴趣的:(MySQL基础)