資料庫常用操作 mysql

2022-08-27 13:06:13 字數 794 閱讀 1290

建立

create database 庫名

create table 表名(列名 type(varchar(size),int(size),decimal(size,d))) "size" 規定數字的最大位數。"d" 規定小數點右側的最大位數。

insert into 表明 (欄位1、欄位2) values ()

更改

#更改表名

alter table 表名 rename 新錶名

#更改欄位中的值

update 表名稱 set 列名稱 = 新值 where 列名稱 = 某值

#更改表欄位名

alter table 表名 change 原欄位名 新欄位名 type

#更改欄位type

alter table 表名 modify 欄位名 type

#增加字段

alter table 表名 add 欄位名 type

#刪除字段

alter table 表名 drop column 欄位名

#刪除表

drop table 表名

#刪除表中資料

delete from 表名 where 列名稱 = 值

#刪除表中所有資料(保留表的資料結構)

truncate 表名

檢視

#檢視表結構資訊(字段、type等)

desc 表名

#檢視表內容

select * from 表名

MySQL資料庫 常用操作

1 使用show語句找出在伺服器上當前存在什麼資料庫 mysql show databases 2 建立乙個資料庫mysqldata mysql create database mysqldata 3 選擇你所建立的資料庫 mysql use mysqldata 按回車鍵出現database cha...

mysql資料庫常用操作

啟動 進入資料後操作 建立資料庫 建立資料表 插入資料 查詢資料庫中所有表的名字 刪除資料表中的字段 新增資料表中的字段 匯出資料庫資料檔案的方法 匯入csv到資料庫中 給已有的資料表增加自增字段 調整mysql欄位順序的方法 查詢資料表中有多少條記錄 更新資料記錄 資料刪除 解決因資料刪除,主鍵 ...

mysql資料庫常用操作

顯示資料庫 show databases 建立資料庫 create database test1 default charset utf8mb4 collate utf8mb4 general ci 使用資料庫 use test1 檢視資料庫字符集 show variables like chara...