一、新建数据库,数据库名为anyun
mysql> create database anyun; Query OK, 1 row affected (0.00 sec)
二、查看数据库
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | anyun | | mysql | | performance_schema | | qqq | +--------------------+ 5 rows in set (0.00 sec)
三、使用数据库
mysql> use anyun; Database changed
四、创建表
mysql> CREATE TABLE world( -> id INT NOT NULL AUTO_INCREMENT, -> name VARCHAR(100) NOT NULL, -> parent_id INT NOT NULL, -> level INT NOT NULL, -> PRIMARY KEY (id) -> )ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.43 sec)
五、查看表结构
mysql> desc world; +-----------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(100) | NO | | NULL | | | parent_id | int(11) | NO | | NULL | | | level | int(11) | NO | | NULL | | +-----------+--------------+------+-----+---------+----------------+ 4 rows in set (0.00 sec)
六、插入数据
mysql> insert into world(name,parent_id,level) values ('上海市',0,1),('北京市',0,1),('湖北省',0,2),('江苏省',0,1),('重庆市',0,2); Query OK, 5 rows affected (0.02 sec) Records: 5 Duplicates: 0 Warnings: 0
七、查询world表的所以数据
mysql> select * from world; +----+-----------+-----------+-------+ | id | name | parent_id | level | +----+-----------+-----------+-------+ | 1 | 上海市 | 0 | 1 | | 2 | 北京市 | 0 | 1 | | 3 | 湖北省 | 0 | 2 | | 4 | 江苏省 | 0 | 1 | | 5 | 重庆市 | 0 | 2 | +----+-----------+-----------+-------+ 5 rows in set (0.00 sec)
八、使用Navicat查看
九、从world表里删除id=1的那行数据
mysql> delete from world where id = 1; Query OK, 1 row affected (0.01 sec)
十、再查看world表里所以的数据,看看id=1的那一行删掉了没有
mysql> select * from world; +----+-----------+-----------+-------+ | id | name | parent_id | level | +----+-----------+-----------+-------+ | 2 | 北京市 | 0 | 1 | | 3 | 湖北省 | 0 | 2 | | 4 | 江苏省 | 0 | 1 | | 5 | 重庆市 | 0 | 2 | +----+-----------+-----------+-------+ 4 rows in set (0.00 sec)