-- 创建数据库 CREATE DATABASE dbname DEFAULT CHARSET utf8 COLLATE utf8_general_ci; -- 创建表 CREATE TABLE `tb` ( `id` int(5) NOT NULL AUTO_INCREMENT, `name` char(15) NOT NULL, `alias` varchar(10) DEFAULT NULL, `email` varchar(30) DEFAULT NULL, `password` varchar(20) NOT NULL, `phone` char(11) DEFAULT '13800138000', PRIMARY KEY (`id`,`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 增加表内数据 进入dbname数据库 mysql> use dbname Database changed # 查看当前库所有的表 mysql> show tables; +------------------+ | Tables_in_dbname | +------------------+ | tb | +------------------+ 1 row in set (0.00 sec) # 查看tb表内的内容 mysql> select * from tb; Empty set (0.00 sec) -- 插入单条数据 insert into tb(name,email,password) values("ansheng","anshengme.com@gmail.com","as"); -- 同时插入多条数据 insert into tb(name,email,password) values("as","i@anshengme.com","pwd"),("info","info@anshengme.com","i"); 查看插入的数据
mysql> select id,name as username from tb where id > 4; +----+----------+ | id | username | +----+----------+ | 5 | hello | | 6 | word | | 7 | python | +----+----------+ 3 rows in set (0.00 sec)