一、创建数据库
mysql> create database school; #创建一个名字为school的数据库
mysql> show databases; #查看数据库
mysql> use school; #进入school数据库
Database changed
mysql> select database(); #查看当前所在库
二、创建表
mysql> create table teacher(
-> id int auto_increment primary key,
-> name varchar(10) null,
-> age int not null,
-> phone char(11) not null
->);
mysql> describe teacher;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(10) | YES | | NULL | |
| age | int(11) | NO | | NULL | |
| phone | char(11) | NO | | NULL | |
+-------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
三、添加表格信息
mysql> insert into teacher (name,age,phone) values("小红",25,17123842348);
mysql> select * from school.teacher where name="小红"
-> ;
+----+--------+-----+-------------+
| id | name | age | phone |
+----+--------+-----+-------------+
| 1 | 小红 | 25 | 17123842348 |
+----+--------+-----+-------------+
1 row in set (0.00 sec)
网友评论