MySQL 資料庫常見操作

2021-07-02 05:44:15 字數 1332 閱讀 1386

建庫語句:

create database plms2 default charset utf8;

建表語句:

帶引號不是英文、中文引號

drop table if exists `zd_test`;

create table `zd_test` (

`rec_id` int(11) not null comment '行標識',

`std_code` varchar(30) not null comment '**',

`std_name` varchar(50) default null comment '名稱',

primary key (`rec_id`)

)comment = '測試表建立'  engine=innodb default charset=utf8;

或者drop table if exists zd_test;

create table zd_test (

rec_id int(11) not null comment '行標識',

std_code varchar(30) not null comment '**',

std_name varchar(50) default null comment '名稱',

primary key (rec_id)

) comment = '測試表建立'  engine=innodb default charset=utf8;

查詢表和字段的注釋

use information_schema;

查詢表的資訊(注釋)

select * from information_schema.tables where 1 = 1 and table_schema='my_db' and table_name = 'zd_test';

查詢欄位的資訊(注釋)

select * from information_schema.columns where 1 = 1 and table_schema='my_db' and table_name = 'zd_test';

[還有一種方式]

show full columns from zd_test;

修改表/欄位的注釋

alter table zd_test comment  = '測試表,修改後';

alter table zd_test modify column rec_id int comment '主鍵id';

MySQL資料庫常見操作

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

MySQL資料庫常見操作

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

MySQL資料庫 常見基本操作

mysql語句的規範 1.關鍵字與函式名稱全部大寫 2.資料庫名稱 表名稱 欄位名稱全部小寫 3.sql語句必須要以分號結尾 作用命令 檢視當前狀態 s 配置檔案中的變數 show variables 顯示當期伺服器版本 select version 顯示當前日期時間 select now 顯示當前...