1. MySQL简介:
MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,后来被Sun公司收购,Sun公司后来又被Oracle公司收购,目前属于Oracle旗下产品。
2. 数据库操作
显示所有的数据库
show databases;
创建数据库
create database 数据库名 charset=utf8;
切换数据库
use 数据库名;
查看数据库中的所有表
show tables;
查看表结构
desc 表名;
3. 数据表操作
创建表
auto_increment 表示自动增长
unsigned 属性就是将数字类型无符号化,表示整型
--例 班级表:
create table classes(
id int unsigned auto_increment primary key not null,
name varchar(10)
);
--例 学生表:
create table students(
id int unsigned primary key auto_increment not null,
name varchar(20) default '',
age tinyint unsigned default 0,
height decimal(5,2),
gender enum('男','女','保密'),
cls_id int unsigned default 0
);
修改表-添加字段
alter table 表名 add 列名 类型及约束;
例:
alter table students add birthday datetime;
修改表-修改字段: 重命名版
alter table 表名 change 原名 新名 类型及约束;
例:
alter table 表名 change birthday birth datetime not null;
修改表-修改字段:不重命名版:
alter table 表名 modify 列名 类型及约束;
例:
alter table students modify date not null;
修改表-删除字段
alter table 表名 drop 列名;
例:
alter table students drop birthday;
删除表
drop table 表名;
例:
drop table students;
查看表的创建语句
show create table 表名;
例:
show create table classes;
4. 数据的增删改查(CURD)
1. MySQL简介:
MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,后来