create database mydatas charset utf8;
show databases;
set names gbk;
show databases like ‘my%‘; -- 查看以my开始的数据库
show create database mydatas;
drop dababase mydatas;
use mydatas;
create table if not exists mydatas.table1(
id int not null primary key,
name varchar(20) not null
)charset utf8;
create table if not exists tabke2(
id int not null primary key auto_increment,
age int not null
)charset utf8;
show tables;
show create table 表名;
show create table table1;
show tables like ‘ta%‘;
desc 表名
desc table1;
describe 表名
describe table1;
show columns from 表名
show columns from table1;
rename table tabke2 to table2;
alter table table1 charset = GBK;
alter table table1 add column uid int first;
alter table table1 add column number char(11) after id;
alter table table1 modify number int after uid;
alter table 表名 change 需要修改的字段名 新的字段名 字段类型(必须存在);
alter table table1 change uid uuid varchar(50);
alter table 表名 drop 字段名;
alter table table1 drop uuid;
dtop table 表名;
drop table table2;
insert into 表名(字段列表) values(对应的字段列表值);
-- 省略自增长的id
insert into t2(name,age) values(‘nordon‘,22),(‘wy‘,21);
-- 使用default、null进行传递字段列表值, id会自动增加
insert into t2 values(null,‘张三‘,22),(default,‘李欧尚‘,21);
-- select 字段名 from 表名 where 条件;
select * from t2 where id = 1;
-- update 表名 set 字段 = 新值 where 条件
update t2 set name = ‘王耀‘ where id = 2;
-- delete from 表名 whrer 条件
delete from t2 where id = 5;
show character set;
show variables like ‘character_set%‘;
-- 修改服务器认为的客户端数据的字符集为GBK
set character_set_client = gbk;
-- 修改服务器给定数据的字符集为GBK
set character_set_results = gbk;
-- 快捷设置字符集
set names gbk;
-- 查看所有校对集
show collation;
-- 创建表使用不同的校对集
create table my_collate_bin(
name char(1)
)charset utf8 collate utf8_bin;
create table my_collate_ci(
name char(1)
)charset utf8 collate utf8_general_ci;
-- 插入数据
insert into my_collate_bin values(‘a‘),(‘A‘),(‘B‘),(‘b‘);
insert into my_collate_ci values(‘a‘),(‘A‘),(‘B‘),(‘b‘);
-- 排序查找
select * from my_collate_bin order by name;
select * from my_collate_ci order by name;
-- 有数据后修改校对集
alter table my_collate_ci collate = utf8_bin;
alter table my_collate_ci collate = utf8_general_ci;
原文:https://www.cnblogs.com/nordon-wang/p/8988075.html