資料庫基礎操作命令之MySQL

2021-10-10 00:12:24 字數 1653 閱讀 3538

主要分為以下五類

是對資料庫中的資料表進行新增 、刪除、修改等操作,不涉及資料庫中表中的內容的操作。ddl更多地由資料庫管理員dba(database administrator)使用。

# 連線mysql伺服器 

mysql -uroot -p 密碼

# 不存在xx資料庫則建立庫

create

database

ifnot

exists 庫名;

# 如果存在xx資料庫則刪除

drop

database

ifexists 庫名;

# 查詢資料庫中有哪些資料庫

show

databases

;# 選擇資料庫並進入

use 庫名;

# 刪除資料庫

drop

database 庫名;

# 建立表

create

table student(欄位名 型別(大小));

# 例如:

create

table student(

name varchar(10

),age int(10

),score int(10));

# 顯示資料庫中建立的所有表

# 檢視表定義

檢視建立表的定義

show

create

table 表名;

刪除表drop

table 表名;

修改表alter

table 表名 modify 欄位名 varchar(20

);增加表字段

alter

table 表名 add

column 欄位名 datatype ;

刪除表字段

alter

table 表名 drop

column 欄位名;

字段改名

alter

table 表名 change 欄位名 新欄位名 datatype ;

change 和modify都可以修改表的定義,不同的是change後面需要寫兩次列名,不方便,但是change的優點是可以修改列名稱,則modify則不能。

# 修改字段排序

# 把字段2放在欄位1後面

alter

table 表名 add 欄位2

date

after 欄位1

;# 把某個字段放在首位

alter

table 表名 modify 欄位名 datatype first;

更改表名

alter

table 表名 rename 新錶名;

後續…

MySql資料庫之資料庫基礎命令

繼續上篇部落格所說到的,使用命令玩轉mysql資料庫。在連線資料庫時,我們需要確定資料庫所在的伺服器ip,使用者名稱以及密碼。當然,我們一般練習都會使用本地資料庫,那麼本地資料庫的連線命令如下 mysql uroot p當我們成功連線資料庫後,先檢視一下當前都有什麼資料庫 show database...

mysql 資料庫基礎查詢操作命令

查詢命令集合 資料庫基礎查詢 以單錶資料查詢所有資料 select from table 查詢表中所有資訊 select id from table select id name from table 查詢表中指定的字段查詢 資料庫條件查詢 以某些資料作為條件進行查詢符合條件的資料 select f...

MySQL 資料庫基礎操作

1.建立資料庫 建立乙個名為db1的資料庫 create database db1 tips 當我們建立資料庫沒有指定字符集和校驗規則時,系統使用預設字符集 utf8 檢視系統支援的字符集 show charset 建立乙個使用utf8字符集的資料庫 create database test1 ch...