# 设置max_connections的值为200 set global max_connections=200;
数据库操作
创建数据库
1 2 3 4
create database 数据库名;
# 创建test数据库 create database test;
删除数据库
1 2 3 4
drop database 数据库名;
# 删除test数据库 drop database test;
显示数据库
1
show databases;
选择数据库
1 2 3 4
use 数据库名称;
# 选择test数据库 use test;
显示数据库的表
1 2 3 4 5
show tables; show tables from 数据库名;
# 显示test数据库的所有表 show tables from test;
显示数据库创建语句
1 2 3 4
show create database 数据库名;
# 显示test数据库的创建语句 show create database test;
设置编码格式
1 2 3 4
alter database 数据库名 character set 编码;
# 设置egame数据库编码为utf8 alter database egame character set utf8;
查看数据库编码格式
1
show variables like 'character%';
表操作
创建表
1 2 3 4 5 6 7 8
create table 表名 (字段 字段类型,...)
# 创建test表 create table test( 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));
表删除
1 2 3 4
drop table 表名;
# 删除test表 drop table test;
显示表结构
1 2 3 4
desc 表名;
# 显示test表的结构 desc test;
显示表创建语句
1 2 3 4
show create table 表名
# 显示test表的创建语句 show create table test;
修改表名
1 2 3
rename table 旧表名 to 新表名 # 修改test表名为test2 rename table test to test2;
表插入数据
1 2 3 4 5 6 7
insert into 表名 [(字段名,...)] values (值,...)
# 向test表插入全部数据 insert into test_table values(3, 'Tom', 1, 96.45);
# 向test_table表插入名字 insert into test_table(name) values('Tom');
删除表数据
1 2 3 4
delete from 表名 where 表达式
# 删除test表id为3的数据 delete from test_table where id=3;