操作MySQL的SQL相關命令

2021-10-08 22:38:58 字數 1436 閱讀 7030

關於mysql操作主要有以下四類:

資料庫建立資料庫

create databse 資料庫名 [character set 字符集];

檢視當前例項的所有資料庫列表

show databases;

刪除資料庫

drop database 資料庫名;

選中/使用資料庫

use 資料庫名;

檢視當前資料庫下的表

show tables;

檢視某個表中的列資訊

desc 表名稱;

檢視某個表的建表語句

show create table 表名稱;

物理刪除某張表

drop table 表名稱;

新增列:

alter table 表名稱 add 列名 型別(長度) [約束];

修改長度及約束

alter table 表名 modify 列名 型別(長度) [約束];

修改列的名字

alter table 表名 change 舊的列名 新的列名 型別(長度) [約束];

刪除列alter table 表名 drop 列名;

重新命名表

rename table 表名稱 to 新的名稱;

插入資料

insert into 表名 (列名1,......) values (值1,.....);

批量插入

insert into 表名 (列名1,....) select 語句(列要對應)更新資料

update 表名 set 欄位1 =值1 , ..... where 條件;刪除資料

delete from 表名 where 條件;查詢所有

select * from 表名

查詢一部分列

select 列1,.... from 表名

查詢的同時指定新的列名

select 列1 as 列名1,..... from 表名 -- as 可以省略

查詢還可以指定常量、及簡單的計算

select 列1,常量,列2*1.1 from 表名

還可以配合distinct 關鍵字來去重

select distinct 列1 from 表名

列1 的結果去重

mysql使用者授權、資料庫許可權管理、sql語法詳解

MySQL使用者相關操作命令

建立命令 create user username host identified by password 引數說明 username是使用者名稱 password是密碼,密碼可以為空 例如 create user test identified by 12345 create user test1...

mysql 的相關操作 mysql 相關操作

mysql u root p 回撤後輸入密碼 123456,進入mysql 資料庫簡單操作 1 建立資料庫 create database 資料庫名稱 2 檢視資料庫 show databases 3 刪除資料庫 drop database 資料庫名稱 4 開啟資料庫 use 資料庫名稱 資料表簡單...

mysql的相關命令列操作命令

1檢視有沒有安裝mysql dpkg l grep mysql 檢測mysql是否安裝成功 netstat tap grep mysql 檢查mysql服務狀態 systemctl status mysql 2登入mysql mysql u root p 顯示所有資料庫 show databases...