目录:
一. MySQL常用增删改查命令
1、创建数据库和表
1. 创建数据库
mysql> show databases;
mysql> create database tomdb charset utf8; #创建数据库tomdb,使用utf-8做字符编码
mysql> use tomdb #选择使用tomdb数据库
mysql> drop database tomdb;
mysql> show create database tomdb; # 查看创建数据库的语法
2.创建表结构
mysql> show tables
mysql> desc student;
mysql> drop table student;
创建表结构:例1
create table student(
id int auto_increment,
name char(32) not null,
age int not null,
register_data date not null,
primary key (id));
mysql> create table student( #在tomdb数据库中创建表:student
-> id int auto_increment, #在表中创建第一个字段:“id”
-> name char(32) not null, #在表中创建第二个字段:“name”
-> age int not null, #在表中创建第三个字段:“age”
-> register_data date not null, #在表中创建第四个字段:日期
-> primary key (id)); #将表的主键设置为字段:“id
Query OK, 0 rows affected (0.10 sec) #这里是创建成功的提示
创建表结构:例2
create table MyClass(
id int(4) not null primary key auto_increment,
name char(20) not null,
sex int(4) not null default '0',
degree double(16,2));
2、插入数据
mysql> desc student; # 查看student表所有字段
mysql> insert into student(name,age,register_data) values("zhangsan",100,"2016-06-20");
mysql> select * from student; #查看student表有哪些数据
3、常用查询语句
1. 最基本查询语句
mysql> select * from student limit 2; #仅查看student表中前两行数据
mysql> select * from student limit 5 offset 3; #从第三行开始查询,并且只显示5行数据
2. where; like; order by;使用
mysql> select * from student where id >3 and age >103;
mysql