MySQL基本用法

2022-07-03 02:45:12 字數 1224 閱讀 8682

一、庫的基本用法

建立資料庫:

#create database 資料庫名 (字符集設定 default character set uft8);

刪除資料庫:

#drop database 資料庫名;(誤刪了可以參考mysql的資料恢復)

檢視資料庫

#show databases;

可以檢視當前有幾個資料庫;分別叫什麼;

檢視某一資料庫的詳細資訊(字符集)

#show create database 資料庫名;

二、表的基本操作;

進行表的操作之前必須要確定對哪乙個資料庫的表操作;

用#use 資料庫;

切換到某一想操作的資料庫上

檢視資料庫:

# show tables;

主要是用於檢視有什麼表;

#show create table 表名;

檢視表的詳細語句;有點類似於建表的時候的語句;

# desc 表名;

檢視表的結構

增:#create:(建立表)

語法規則:

create table 表名(

欄位名1  資料型別 (解釋)  約束條件,

欄位名2  資料型別 (解釋)  約束條件,

);解釋的寫法:     comment 『注釋內容』

約束:unique 唯一約束,顧名思義

not null    非空約束,此資料插入不可以為空

primary key    主鍵約束,用於標識表的記錄,不允許為空,可以加快查詢速度;

建立表的時候不可以同名;

改表名:

#alter table 舊表名 rename to 新錶名;

修改欄位的資料型別;

#alter table 表名 modify 欄位名 新資料型別

修改欄位名(也可以修改資料型別)

#alter table dbname change 欄位名 新欄位名 資料型別;

增加字段;

#alter table dbname add 欄位名 資料型別 約束條件  放在哪(first或者after 哪個)

刪除字段;

#alter table dbname drop 欄位名;

刪除表;

#drop table tablename

即使沒有也可以不報錯,加上if exist的話

mysql 的基本用法 mysql基本用法

mysql 5.1 中文參考手冊 show databases 顯示資料庫 drop database 資料庫名 刪除資料庫 set names utf8 設定資料庫編碼為utf 8 source x 資料庫名.sql 匯入乙個資料庫 use 資料庫名 嘗試訪問資料庫 create database...

mysql 的基本用法 mysql基本用法

mysql 5.1 中文參考手冊 show databases 顯示資料庫 drop database 資料庫名 刪除資料庫 set names utf8 設定資料庫編碼為utf 8 source x 資料庫名.sql 匯入乙個資料庫 use 資料庫名 嘗試訪問資料庫 create database...

MySQL基本用法

mysql基本操作 注意全英文 啟動 開始 mysql command line client 使用者名稱 root,密碼 顯示資料庫 show database 使用資料庫 use 庫名 use mysql 顯示資料庫表 show tables 顯示表結構 describe 表名 如 descri...