MySQL的資料庫定義語法

2022-08-26 10:21:07 字數 1538 閱讀 2237

在mysql中,使用 create database 或 create schema 語句建立資料庫

語法結構:

create [if not exists] db_name

[default]character set [=]charest_name

|[default]collate [=]collation_name

: 表示為可選

|: 用於分隔花括號中的選項,表示任選一項語法

db_name: 標識具體的資料庫命名,必須符合作業系統資料夾命名規則,在mysql中不區分大小寫

default: 預設值

charest set: 指定資料庫字符集

collate: 指定字符集校對規則

if not exists:建立資料庫前進行判斷,只有該資料庫不存在時才能建立資料庫

example:

建立名稱位 mysql_test 的資料庫

create database mysql_test;
在次輸入同樣的命令 將會報錯 可新增if not exists避免報錯

mysql 中建立資料庫之後,不會自動使用新建立的資料庫,可使用use語句從當前環境切換換至新建立的資料庫或其它資料庫

example:

use mysql_test;
alter [db_name]
example:

修改已有資料庫預設字符集和校對規則

alter database mysqle_test

...

mysql 中使用 drop database 或 drop schema 來刪除資料庫,其資料永久刪除

語法結構:

drop [if exisits]db_name
example:

drop database if exisits  mysqle_test

...

mysql 中使用 show database 或 show schema 來看可用資料庫列表,只會列從出許可權範圍內的資料庫

語法結構:

show [like'pattern'|where expr]
like: 匹配指定資料庫名稱

where: 指定資料庫名稱查詢範圍

example:

show database
owen 的個人部落格

mysql的資料庫定義 MySQL的資料庫定義語法

建立資料庫 在mysql中,使用 create database 或 create schema 語句建立資料庫 語法結構 create if not exists db name default character set charest name default collate collatio...

mysql資料庫基本語法 MySQL資料庫基本語法

toc sqlwhat sql是什麼?structured query language 結構化查詢語 why 為何要使用sql?難道僅僅使用sql server management studio運算元據庫?應用程式如何與資料庫打交道?when 何時使用?對sql server執 所有的操作都可以...

mysql資料庫語法 MySQL資料庫操作語法詳解

1 資料庫建立 建庫語句如下 create database schema會建立乙個給定名稱的資料庫,只有擁有create許可權才能使用該語法。不加if not exists時,如果需要建立資料庫已經同名存在則會報錯。create specification中指定了建立資料庫特性。資料庫特性存放在資...