前言:呈現(xiàn)的是非?;A必備命令以及常規(guī)關聯(lián)語法,因涉及到不同數(shù)據(jù)庫其表達都會有所區(qū)別,此篇純屬做個倉庫記錄更非常規(guī)持續(xù)更新,專業(yè)人士可忽略,且看且珍惜…
MySQL: 關系型數(shù)據(jù)庫、重點開源、支持大型規(guī)模、標準SQL數(shù)據(jù)語言、多平臺多架構(gòu)、高可用集群、可定制開發(fā)等等、此測試環(huán)境為MySQL5.7社區(qū)版
登入MySQL
mysql -uroot -p
查看數(shù)據(jù)庫版本
select @@version; 或 select version();
select user(); --查看當前用戶
查詢數(shù)據(jù)庫
show databases;
查看當前數(shù)據(jù)庫
select database();
查詢所有表
use test237 -- 切入對應數(shù)據(jù)庫
show tables;
查詢單庫的所有表
select table_name from information_schema.tables where table_type = 'base table' and table_schema = 'test237';
遷移表到指定數(shù)據(jù)庫
# 復制表結(jié)構(gòu)
CREATE TABLE target_database.table_name LIKE source_database.table_name;
create table test237.db1_1 like db1.db1_1;
# 導入數(shù)據(jù)
INSERT INTO target_database.table_name SELECT * FROM source_database.table_name;
insert into test237.db1_1 select * from db1.db1_1;
#-----------#
創(chuàng)建數(shù)據(jù)庫
create database test237 default character set utf8;
創(chuàng)建表
create table test1(ID char(10),NAME char(20) ,SEX char(4),AGE int(10));
創(chuàng)建用戶
create user mysqluser identified by '123456';
授予用戶權(quán)限
grant all on *.* to 'test'@'%';
GRANT 權(quán)限 ON 數(shù)據(jù)庫.表 TO 用戶名@登錄主機 identified by '密碼'
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' identified by 'password'
grant all privileges on *.* to 'test'@'localhost' identified by '123456';
刷新權(quán)限
flush privileges
查看用戶權(quán)限(ALL/單個)
show grants;
show grants for 'username'@'localhost';
show grants for 'root'@'%';
查看用戶
select user from mysql.user;
刪除用戶
drop user 'test'@'localhost';
drop user 'test'@'%';
#-----------#
創(chuàng)建視圖
語法:create view 視圖名 as select選取的列名1,選取的列名2.... from 源表;
create view view_name as select column1, column2 FROM table_name;
mysql> create view view_test1 as select ID,NAME from test1;
查看視圖
mysql> select * from view_test1;
刪除視圖
drop view view_name;
drop view IF EXISTS view_name;
#-----------#
創(chuàng)建表添加主鍵
CREATE TABLE table_name (id INT,name VARCHAR(50),PRIMARY KEY (id));
已存在表添加主鍵
alter table table_name add primary key(ID);
刪除主鍵
alter table table_name drop primary key(ID);
//一個數(shù)據(jù)表只可以有一個主鍵,所以不存在刪除某一列的主鍵
#-----------#
創(chuàng)建索引
//創(chuàng)建索引/刪除索引索引不可以更改,想更改必須刪除重新建
create index index_name on table_name (column_name);
//其中,index_name為要創(chuàng)建的索引名稱,table_name為要添加索引的表名,column_name為要添加索引的列名。
在多列上創(chuàng)建復合索引(聯(lián)合索引)
create index index_name on table_name (column1, column2, ...);
# 刪除索引
drop index index_name;
drop index idxname on table_name;
查看某個表的索引
show index from table_name
//其中,table_name為需要查詢索引的表名稱。輸出結(jié)果將包含該表的索引信息,包括索引名、列名、索引類型等。
#-----------#
其它命令集合:
select * from dba_blockers; --查詢鎖
select * from dba_waiters; --查詢被阻塞的會話
select column_name from tab_old intersect select column_name from tab_new; --顯示兩表的相同數(shù)據(jù)
select @@version; 或 select version(); --查看數(shù)據(jù)庫版本
select database(); --查看當前數(shù)據(jù)庫
select user(); --查看當前用戶
show tables; --查看所有表
show columns from tablename; --查看表中的列的基本信息
desc table; 或 describe table; --表名后加字段名,查看該字段基本信息
select CHARACTER_LENGTH(ID) from tablename; --查詢該字段值的長度
#-----------#文章來源:http://www.zghlxwxcb.cn/news/detail-824551.html
MySQL:先創(chuàng)建一個企業(yè)數(shù)據(jù)做演示驗證:
進入MySQL查出所有的數(shù)據(jù)庫文件
mysql -uroot -p
show databases;
show tables;
#-----------#文章來源地址http://www.zghlxwxcb.cn/news/detail-824551.html
創(chuàng)建test237數(shù)據(jù)庫、test1表、錄入數(shù)據(jù)
show databases;
新建數(shù)據(jù)庫test237并指定字符編碼為UTF8
create database test237 default character set utf8;
查詢test數(shù)據(jù)庫的字符編碼
select schema_name,default_character_set_name from information_schema.schemata where schema_name = 'test237';
創(chuàng)建test1表
mysql> create table test1(I
到了這里,關于Oracle、MySQL數(shù)據(jù)庫常規(guī)命令語法-簡易記錄(非常規(guī)持續(xù)更新)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!