一、下载:
Windows下载MySQL教程:
教程链接
二、基础语法:
1、连接数据库 :在命令提示符下输入:mysql -u root -p
2、创建数据库 :create database <数据库名>;
例:创建一个名为Hello的数据库可输入:create database Hello;
3、删除数据库:drop database <数据库名>;
例:删除一个名为Hello的数据库可输入:drop database Hello;
4、选择数据库:使用数据库时,需要先选择使用哪个数据库,于是就要用到如下的命令:use <数据库名>
在使用该命令后,后续操作都在该数据库里进行
5、创建数据表:create table <数据表名> (表字段名 表字段类型);
例:创建一个名为City的表,该表具有province,country,population三个表字段
create table city (province varchar(100) not null,
country varchar(100) not null,
population int not null);
6、删除数据表:drop table <数据表名> [where condition];
7、插入数据:
insert into <数据表名> (表字段名,表字段名...) values (增添数据,增添数据...);
例:在上表city中添加数据(四川,中国,8000)
insert into city (province,country,population) values (“四川”,“中国”,8000);
8、读取数据表: select * from <数据表名>;
例:select * from city;
9、查询数据:
select <待查询列表> from <数据表名>[where 条件] [limit N][ offset M];
(1) where :
支持多个条件,多个条件之间连接使用and,or来连接。
条件支持:=, != ,>,<,>=,<=
(2) limit :
限制语句 limit学习链接
(3) offset
例:在city表中查询country和population
select country,population from city;
例:在city表中查询country为中国,population小于10000的数据
select * from city where country=“中国” and population<10000;