mysqld/mariadb常用语句

create database if not exists hidb; #创建库,如果此库不存在
show warnings; #查看db最近一次的告警
alter database hidb character set 'utf-8'; #设置数据库字符集
drop database testdb; #删除库
show databases like '%db'; #查询以db结尾的数据库信息
help show databases; #帮助

create table tbl2 (id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE KEY,name VARCHAR(60) NOT NULL); #创建表结构

create table tbl2 (id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT ,name VARCHAR(60) NOT NULL,UNIQUE KEY(id,name)); #创建表结构

help desc; #帮助
describe city; #查询表结构
DESC tbl2; #查询表结构

show engines; #查看支持的引擎
show table status; #查看所有表状态信息
show table status like 'tablename'\G; #查看单表状态信息
show table status where name like 'table'; #查看以table开头的表
show table status where Engine='MyISAM'; #查询引擎为MyISAM的表状态
alter table tbl3 ADD gender ENUM('F','M'); #修改表结构,新增枚举字段
alter table tbl3 CHANGE id stuid SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY; #修改字段名 id 为 stuid
alter table tbl3 ADD INDEX (name); #创建索引
show INDEXES from tbl3; #查看表中的所有索引
alter table tbl3 drop index id; #删除id字段的索引
alter table tbl3 drop primary key id; #删除id字段的主键
create table tbl4 like mysql.user; #创建tbl4表,从mysql.user复制表结构
create table tbl5 select host,user,passwd from mysql.user; #查询mysql.user表中的字段及内容,放到新创建的表中
create index indexname on tabl5(id); #创建索引

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章