select 从数据库中提取数据
update 更新数据库中的数据 (update table set "index=value" where index=value)
delete 从数据库中删除数据 (delete from table where index=value)
insert into 向数据库中插入新数据
create database 创建新的数据库
alter database 修改数据库
create table 创建新表
alter table 更新/改变数据表内容
drop table 删除数据表
create index 创建索引/搜索键
drop index 删除索引
distinct index 去除index中的重复值 (select distinct index from table)
where 在查询中进行定位,可与and和or配合使用
order by index 对查询结果进行排序 (order by index desc 降序)
limit number 限制提取数据的条数
案例
//使用数据库
mysql> use practice;
Database changed
//创建数据表语句
mysql> create table if not exists website(
-> id int not null auto_increment,
-> name char(10) not null,
-> url char(40) not null,
-> alexa int not null,
-> country enum("CN","USA"),
-> primary key(`id`)
-> )engine=innodb default charset=utf8mb4;
Query OK, 0 rows affected (0.05 sec)
//查看建表语句
mysql> show create table website;
+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| website | CREATE TABLE `website` (
`id` int NOT NULL AUTO_INCREMENT,
`name` char(10) NOT NULL,
`url` char(40) NOT NULL,
`alexa` int NOT NULL,
`country` enum('CN','USA') DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
//查询表中是数据
mysql> select * from website;
+----+--------------+---------------------------+-------+---------+
| id | name | url | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1 | Google | https://www.google.cm/ | 1 | USA |
| 2 | 淘宝 | https://www.taobao.com/ | 13 | CN |
| 3 | 菜鸟教程 | http://www.runoob.com/ | 4689 | CN |
| 4 | 微博 | http://weibo.com/ | 20 | CN |
| 5 | Facebook | https://www.facebook.com/ | 3 | USA |
+----+--------------+---------------------------+-------+---------+
5 rows in set (0.00 sec)
//distinct 删除重复值
mysql> select distinct country from website;
+---------+
| country |
+---------+
| USA |
| CN |
+---------+
2 rows in set (0.00 sec)
//