MySQL資料庫 常見基本操作

2021-07-22 15:48:25 字數 1703 閱讀 9859

mysql語句的規範:

1.關鍵字與函式名稱全部大寫

2.資料庫名稱、表名稱、欄位名稱全部小寫

3.sql語句必須要以分號結尾

作用命令

檢視當前狀態:

\s

配置檔案中的變數:

show variables;

顯示當期伺服器版本

select version();

顯示當前日期時間

select now();

顯示當前使用者

select user();

顯示當前所在庫

select database();

檢視當前所有資料庫

show databases;

檢視當前的資料表

show tables;

檢視警告資訊(出現警告)

show warnings;

檢視約束關係(\g格式輸出)

show indexes from 表名\g;

檢視索引關係(\g格式輸出)

show index from 表名\g;

檢視建立表時的命令

show create table 表名;

幫助:?

退出:exit

!操作時,後面的「;」 千萬別忘了

作用命令

先輸入密碼登入mysql -h localhost -u root -p密碼

後輸入密碼登入mysql -h localhost -u root -p

換埠後登入mysql -h localhost -u root -p密碼 -p埠號

其它伺服器登入mysql -u root -p密碼 -h伺服器位址

切換資料庫use 資料庫名;

新建資料庫(即資料夾)

create database 資料庫名稱;

刪除資料庫drop database 資料庫名稱;

修改資料庫alter database 資料庫名稱 [default] character set [=] charset_name

推薦程式設計裡加入if語句,這樣不會有錯誤,只會warning

如下新建資料庫(if not exists即沒有此資料庫時,執行新建命令)

create database if not exists 名稱;

刪除資料庫(if exists即有此資料庫時,執行刪除命令)

drop database if exists 名稱;

新建表create if not exists 庫名.表名 (id int, name char(30)…);

MySQL資料庫常見操作

1.為所有使用者授權 grant all privileges on to 使用者名稱 identified by 密碼 2.資料庫基礎操作 1 登陸mysql資料庫 mysql u root p,回車後再輸入密碼即可 2 檢視所有資料庫 show databases 3 刪除某個資料庫 drop ...

MySQL 資料庫常見操作

建庫語句 create database plms2 default charset utf8 建表語句 帶引號不是英文 中文引號 drop table if exists zd test create table zd test rec id int 11 not null comment 行標識...

MySQL資料庫常見操作

資料庫連線與關閉 mysql h 伺服器主機位址 u 使用者名稱 p 使用者密碼 建立新使用者並授權 grant 許可權 on 資料庫.資料表 to 使用者名稱 登入主機 identified by 密碼 建立資料庫 create database if not exists 資料庫名 刪除資料庫 ...