1 创建并选择数据库
如果系统管理员在设定我们权限时创建了我们的数据库,那么我们可以直接使用数据库。否则我们需要自己进行创建:
mysql> CREATE DATABASE menagerie;
在Unix系统下,数据库名字是区分大小写的(不同于SQL关键字),所以我们要使用上面创建的数据库时,需要指定为menagerie
。This is also true for table names. (Under Windows, this restriction does not apply, although you must refer to databases and tables using the same lettercase throughout a given query. However, for a variety of reasons, the recommended best practice is always to use the same lettercase that was used when the database was created.)
注意:
If you get an error such as ERROR 1044 (42000): Access denied for user ‘micah’@‘localhost’ to database ‘menagerie’ when attempting to create a database, this means that your user account does not have the necessary privileges to do so. Discuss this with the administrator or see Section 6.2, “Access Control and Account Management”.
待补充:
https://dev.mysql.com/doc/refman/8.0/en/creating-database.html
创建一个数据库后我们并没有选择这个数据库,我们必须手动指定这个数据库。为了使得menagerie
为当前数据库,我们需要使用如下语句:
mysql> USE menagerie
Database changed
待补充:
https://dev.mysql.com/doc/refman/8.0/en/creating-database.html
2 创建数据库的表
创建了数据库后,此时数据库为空,利用如下语句可以进行观察:
mysql> SHOW TABLES;
Empty set (0.00 sec)
接下来我们需要决定我们的数据库的结构:即我们需要哪些表,这些表中都有哪些列。