mysql> drop database if exists jianghu; 创建一个新的数据库,如果存在则删除后建立;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> create database jianghu;
Query OK, 1 row affected (0.00 sec)
mysql> show databases; 显示数据库信息;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mydb |
| mysql |
| students |
| test |
| testdb |
+--------------------+
6 rows in set (0.01 sec)
mysql> use jianghu; 选择数据库;
Database changed
创建一张表,id为主键
mysql> create table student(id int(3) auto_increment not null primary key,
-> name char(10) not null,
-> age int(2) not null,
-> course varchar(40),
-> entertime date)
-> ;
Query OK, 0 rows affected (0.05 sec)
mysql> show tables; 显示表信息;
+-------------------+
| Tables_in_jianghu |
+-------------------+
| student |
+-------------------+
1 row in set (0.01 sec)
mysql> desc student; 显示表结构
+-----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+----------------+
| id | int(3) | NO | PRI | NULL | auto_increment |
| name | char(10) | NO | | NULL | |
| age | int(2) | NO | | NULL | |
| course | varchar(40) | YES | | NULL | |
| entertime | date | YES | | NULL | |
+-----------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
插入数据到表:
mysql> insert into student(id,name,age,course)values(1,'linghu',18,'dugujiujian');
Query OK, 1 row affected (0.00 sec)
mysql> SELECT * FROM student;
+----+--------+-----+-------------+-----------+
| id | name | age | course | entertime |
+----+--------+-----+-------------+-----------+
| 1 | linghu | 18 | dugujiujian | NULL |
+----+--------+-----+-------------+-----------+
1 row in set (0.00 sec)