MySQL适合初学者反复练习的基本SQL语句

唯熟能尔

mysql> #清屏:system cls
mysql>system cls

mysql> #查所有数据库
mysql> show databases;

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| testdb             |
| world              |
+--------------------+
7 rows in set (0.01 sec)

mysql> #删除testdb数据库
mysql> drop database testdb;
Query OK, 1 row affected (0.02 sec)

mysql> #新建testdb数据库
mysql>create database testdb;
Query OK, 1 row affected (0.01 sec)

mysql> #选择testdb数据库
mysql> use testdb
Database changed

mysql> #新建test数据表,表结构2个数据类型int的id,varchar的name
mysql> create table test(id int comment "编号",name varchar(50) comment "姓名")comment "测试表";
Query OK, 0 rows affected (0.03 sec)

mysql> #查询刚才新建的test数据表
mysql> show tables;

+------------------+
| Tables_in_testdb |
+------------------+
| test             |
+------------------+
1 row in set (0.01 sec)

mysql> #查询test数据表结构
mysql> desc test;

+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int         | YES  |     | NULL    |       |
| name  | varchar(50) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.01 sec)

mysql> #数据表有了,插入一条数据
mysql> insert into test(id,name)values(1,"admin");
Query OK, 1 row affected (0.01 sec)

mysql> #查询test数据表中所有数据
mysql> select * from test;

+------+-------+
| id   | name  |
+------+-------+
|    1 | admin |
+------+-------+
1 row in set (0.00 sec)

mysql> #删除这条数据
mysql> delete from test where id=1;
Query OK, 1 row affected (0.01 sec)

mysql> #删除test数据表
mysql> drop table test;
Query OK, 0 rows affected (0.03 sec)

mysql> #删除testdb数据库
mysql> drop database testdb;
Query OK, 0 rows affected (0.02 sec)

mysql>

posted @ 2022-03-03 18:37  TabKey9  阅读(94)  评论(0编辑  收藏  举报