1.登录MySQL
单击开始->所有程序->MySQL命令提示符->输入密码root即可
2.MySQL的使用
-
创建数据库test1
create database test1; ||create schema test1;
-
查看所有数据库
show databases;
-
选择数据库test1
use test1;
-
查看表信息
show tables;
-
查看创建表的结构
desc 表名; ||describe 表名;
-
一次性的设置client,connection,results的字符集为GBK
set names GBK;
-
查看mysql字符集
show variables like 'character%';
-
向表中插入记录
insert into 表名 values(‘’,‘’,‘’,‘’,‘’);
-
查询表中的信息
select * from 表名;
10.删除表
drop table 表名;
-
删除数据库
drop database 数据库名;
-
查看服务实例支持的字符集,字符序
show character set;
13.复制表结构
create table 新表名 like 原表名;
14.修改表名
rename table 原表名 to 新表名;
15.修改表
alter table 表名
add 字段名1 数据类型 [约束条件] [first|after 字段名2];
change 字段名1 新字段名 数据类型 [约束条件] [first|after 字段名2];
modify 字段名1 新数据类型 [约束条件] [first|after 字段名2];
drop 字段名;
rename [to] 新表名;
例如:
- alter table ygb add yjyj char(2) not null first;
- alter table ygb change yjyj xyz int(2) ;
- alter table ygb modify y varchar(10);
- alter table ygb drop address;
- alter table ygb rename to yg;
16.关键字
- 默认值:default ‘值’
- 自增型:auto_increment(默认从1开始自增)
- 设置取值范围:check(sex in(‘男’,‘女’)) || check(sex=‘男’ or sex=‘女’)
例如:
create table employees2(
EmployeeID int(6) not null primary key auto_increment,
Name char(10) not null,
Education char(4) not null,
Birthday date not null,
Sex char(2) check(sex='男' or sex='女'), || Sex char(2) check(Sex in('男','女')),
WorkYear tinyint(1),
Address varchar(20),
PhoneNumber char(13),
DepartmentID char(3) not null
);