mysql資料庫常用操作

2021-08-21 11:49:05 字數 1509 閱讀 8870

顯示資料庫 

show databases; 

建立資料庫 

create database test1 default charset utf8mb4 collate utf8mb4_general_ci; 

使用資料庫 

use test1; 

檢視資料庫字符集 

show variables like 'character%'; 

啟動mysql服務(cmd中執行,mysql57是服務名,可以在任務管理器中的服務欄中查到) 

net start mysql57 

停止mysql服務 

net stop mysql57 

建立使用者 

create user '使用者名稱'@'ip位址' identified by '密碼'; 

刪除使用者 

drop user '使用者名稱'@'ip位址'; 

修改使用者 

rename user '使用者名稱'@'ip位址'; to '新使用者名稱'@'ip位址';;

7.查詢表中字段資訊

show full fields from tablename;

8.查詢表中索引資訊

show index from tablename;

9.查詢使用者的許可權

show grants for 使用者名稱

10.增加分割槽

alter table tablename add partition (partition p_20160102 values in (20160102)); 

12.查詢建表語句

show create table tablename;

11.查詢資料庫中的所有表

select table_name from information_schema.tables  

13.統計資料庫中每個表的資料量

select table_name,table_rows from tables

where table_schema = 'xx'

order by table_rows desc;

查詢資料庫所有表結構資訊

select * from information_schema.tables where table_schema='xx';

刪除字段

alter table ob_corderdetail 

drop column carshopserway,

drop column carshopcode,

drop column carshopname,

drop column carshopaddr,

drop column carshoptel;

新增字段

alter table ob_saleorderitem add

(isdelockventory       varchar(1) comment '是否鎖庫存成功,0未扣減,1已扣減'  null

);

MySQL資料庫 常用操作

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

mysql資料庫常用操作

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

mysql資料庫常用操作

資料庫操作 建立資料庫 create database schema if not exists db name character set character set name collate collate name 修改資料庫 alter database db name character ...