Mysql資料庫基礎知識點總結

2021-10-05 00:08:39 字數 3563 閱讀 8475

create database database_name;    //建立資料庫

create database database_name character set=gbk/utf8; //建立指定字符集的資料庫

create database if not exists database_name; //建立資料庫前判斷是否存在同名資料庫

show databases;  //檢視資料庫

show create database 庫名; //顯示資料庫建立資訊

select database(); //檢視當前資料庫

alter database database_name default character set gbk/utf8; //設定預設字符集

drop database database_name; //刪除資料庫

create table 表名(欄位名1 型別(長度) [約束],欄位名2 型別(長度) [約束],......);//建立資料表

show tables; //檢視資料表

desc table_name; //檢視表結構

alter table table_name add 列定義 [first/after 列名]; //向表中新新增列,內表示在某列的前或後新增,不指定則新增到最後

alter table table_name change 列名 原列名; //列名重定義

alter table table_name modify 列定義; //修改列資料型別

alter table table_name drop 列名; //刪除列

alter table table_name rename 新錶名; //重新命名該錶

alter table table_name order by 列名; //排序

alter table table_name alter 列名 //指定修改預設值或刪除

drop table table_name; //刪除表

create table table_name1 like table_name2; //建立乙個結構相同的空表

create user 使用者 identified by 'password'; //建立新使用者  使用者='使用者名稱'@'主機名'

drop user 使用者; //刪除使用者

grant privileges on database_name.table_name to 使用者; //授權使用者許可權 table_name可用*代表所有表

revoke privileges on daatabase_name.table_name from 使用者; //**使用者許可權

其中privileges可以包含:create,alter,drop:庫/表結構操作

select,insert,delete,update:資料操作

references:外來鍵許可權

index:索引

rename user 老使用者 to 新使用者; //修改使用者名稱

set password for 使用者=password('新密碼'); //修改使用者密碼

drop user 使用者; //刪除使用者

insert into table_name(列名1,列名2,...)  values  (記錄1,記錄2,...),(記錄1,記錄2,...),(...); //插入新記錄方式一,可插入多條

insert into table_name set 列名1=記錄1,列名2=記錄2,...; //插入新記錄方式二

insert into table_name1 select * from table_name2; //從已有的表中插入資料進來

insert into database_name1.table_name1 select * from database_name2.table_name2; //從乙個庫的一張表記錄插入到另乙個庫的另一張表中

update table_name1,table_name2,... set 列名1=expr1,列名2=expr2,...  where 條件; //修改表資料

update table_name1 a,table_name2 b set a.列名1=b.列名2 where 條件; //將表1的列名1設定成跟表2的列名2一樣

delete from table_name;  //刪除資料表中的所有記錄

delete from table_name where 條件; //刪除滿足條件的行

例:delete user1,user2 from user1,user2,user where user1.id=user.id and user2.id=user.id; //刪除user1中id值等於user的所有行和user2的id值等於user的id值的所有行

show tables或 show tables from database_name; //顯示當前資料庫中所有表名稱

show databases; //顯示所有資料庫的名稱

show columns from table_name from database_name 或 show columns from database_name.table_name; //顯示表中列的名稱

show grants for user_name; //顯示乙個使用者的許可權,顯示結果類似於grant命令

show index from table_name; //顯示表的索引

show status; // 顯示一些系統特定資源的資訊,例如正在執行的執行緒數量

show variables; //顯示系統變數的名稱和值

show processlist; //顯示系統中正在執行的所有程序

show table status; //顯示當前使用或者指定的database中的每個表的資訊;

show privileges: //顯示伺服器所支援的不同許可權。

show create database database_ name: //顯示建立某乙個資料庫的createdatabase語句。

show create table table_name: //顯示建立乙個表的 create table語句。

show events; //顯示所有事件的列表。

show innodb status; //顯示innodb儲存引擎的狀態。

show logs; //顯示bdb儲存引擎的日誌。

show warnings; //顯示最後乙個執行的語句所產生的錯誤、警告和通知

show errors; //只顯示最後-乙個執行語句所產生的錯誤。

show [storage] engines; //顯示安裝後的可用儲存引擎和預設引擎。

show procedure status; //顯示資料庫中所有儲存過程基本資訊,包括所屬資料庫、儲存過程名稱、建立時間等。

show create proceduresp_name; /顯示某乙個儲存過程的詳細資訊。

MySql資料庫基礎知識點總結

本文例項講述了mysql資料庫基礎知識點。分享給大家供大家參考,具體如下 資料表在建立時,需為每個字段選擇資料型別,而資料型別的選擇則決定著資料的儲存格式,有效範圍和對應的限制 mysql提供了多種資料型別,主要分為3類 在資料庫中,資料表設計的是否合理直接影響著資料庫的功效,而在設計資料表時儲存引...

Mysql資料庫基礎知識點(下午) 二

create table teacher id int,name varchar 20 salary float 4,2 insert into teacher value 1,老邊 23.23 select distinct chinese from student 1.在所以學生的英語分數上加上...

資料庫原理 基礎知識點

基本概念 1 資料庫定義為關聯記錄的自描述集合 2 關於資料庫結構的資料稱為元資料。表名 列名和列所屬的表 表和列的屬性等都是元資料 3 資料庫系統四個組成部分 使用者 資料庫應用程式 資料庫管理系統 dbms 和資料庫 4 sql 結構化查詢語言,是處理關聯式資料庫中表的國際語言 5 鍵 標識表中...