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); #創建索引

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