-- 創(chuàng)建數(shù)據(jù)庫 CREATE DATABASE dbname DEFAULT CHARSET utf8 COLLATE utf8_general_ci; -- 創(chuàng)建表 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; 增加表內(nèi)數(shù)據(jù) 進(jìn)入dbname數(shù)據(jù)庫 mysql> use dbname Database changed # 查看當(dāng)前庫所有的表 mysql> show tables; +------------------+ | Tables_in_dbname | +------------------+ | tb | +------------------+ 1 row in set (0.00 sec) # 查看tb表內(nèi)的內(nèi)容 mysql> select * from tb; Empty set (0.00 sec) -- 插入單條數(shù)據(jù) insert into tb(name,email,password) values("ansheng","anshengme.com@gmail.com","as"); -- 同時插入多條數(shù)據(jù) insert into tb(name,email,password) values("as","i@anshengme.com","pwd"),("info","info@anshengme.com","i"); 查看插入的數(shù)據(jù)
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)