数据库-操作数据库

命令行登录

mysql -h 127.0.0.1 -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.20 MySQL Community Server - GPL

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


创建数据库

**创建数据库 无论大小写 都可以创建 那么会有这样创建组合 :GAME game **
可以是 GaME gaMe 但最后整个效果是 game只认小写 这样的当然创建数据库是为了应用才创建 去使用!当然创建数据库就像一个空仓库 货物,以及 货物 都为空 当然本来空 填充这些货物称之为

create database databaseName;

演示:

mysql> create database GAME;
Query OK, 1 row affected (0.01 sec)

查看 当前 所有的数据库

查看所有数据库

包括 数据库系统, 用户自己创建数据库

show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| world              |
+--------------------+
6 rows in set (0.01 sec)

选择或者说使用数据库

use  databaseName;
 use game
Database changed
mysql> show tables;
Empty set (0.01 sec)

mysql> use world
Database changed
mysql> show tables;
+-----------------+
| Tables_in_world |
+-----------------+
| city            |
| country         |
| countrylanguage |
+-----------------+
3 rows in set (0.00 sec)

world 是系统简单的示例
作为 一些新手 的练手必备 当然删除这个数据库也没什么 主要是不要把其他的都删了

删除数据库

drop database databaseName;

删除数据库 慎用 无论大写或者小写都 只要能匹配上的数据库名字都能删除
比如说创建一个名Game 的数据库 无论大小写 都可以删除 那么会有这样删除组合 :GAME game gAme GaMe

mysql> create database Game;
Query OK, 1 row affected (0.15 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| game               |
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| world              |
+--------------------+
7 rows in set (0.04 sec)
mysql> drop database GAME;
Query OK, 0 rows affected (0.12 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| world              |
+--------------------+
6 rows in set (0.00 sec)
mysql> create database Game;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| game               |
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| world              |
+--------------------+
7 rows in set (0.00 sec)
mysql> create database Game_infor;
Query OK, 1 row affected (0.02 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| game               |
| game_infor         |
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| world              |
+--------------------+
8 rows in set (0.00 sec)
mysql> drop database game;
Query OK, 0 rows affected (0.04 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| game_infor         |
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| world              |
+--------------------+
7 rows in set (0.00 sec)
mysql> create database  GaMeInfor;
Query OK, 1 row affected (0.01 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| gameinfor          |
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| world              |
+--------------------+
7 rows in set (0.00 sec)

mysql> drop database GaMe;
ERROR 1008 (HY000): Can't drop database 'game'; database doesn't exist
// 错误1008(HY000):无法删除数据库“game”;数据库不存在

还以为 删除不明确的 没想到居然 指定的删除 还真是 指定删除库 不过还好这里面没数据

居然创建也是如此 还真得好好的命名数据库名称

你可能感兴趣的:(小森数据库技术总结,数据库)