建立mysql資料庫總結 MySQL資料庫總結

2021-10-18 03:12:32 字數 1964 閱讀 1932

引擎

檢視mysql預設引擎:

show variables like '%storage_engine%';

檢視表引擎:

show table status from 資料庫名;

修改表引擎

alter table 表名 engine=innodb;

建立時直接定義引擎

create table 表名() engine=innodb;

編碼資料庫中檢視字串編碼:

show variables like'character%';

修改資料庫中表的編碼:

alter table 表名 convert to character set utf8;

檢視資料庫中表的編碼(顯示完整的建表語句)

show create table 表名

建立資料庫時指定資料庫的字符集:

create database 資料庫名 character set utf8;

建立資料表時指定資料表的編碼格式:

create table tb_books (

name varchar(45) not null,

price double not null,

bookcount int not null,

author varchar(45) not null ) default charset = utf8;

修改字段編碼格式:

alter table change character set utf8;

增刪改查

增加:insert into 資料庫名 values(內容)

insert into 資料庫名(字段) values(內容)

刪除:delete from 表名 where 字段

改寫:update 表名 set 更改內容(name=1) where id=1

查 :select * from 表名

修改表結構

alter table 表名 change 舊欄位名 新欄位名 字段型別

索引1.普通索引

2.唯一索引

3.全文索引

4.單列索引

5.多列索引

6.空間索引

7.主鍵索引

8.組合索引

普通索引:僅加速查詢

唯一索引:加速查詢 + 列值唯一(可以有null)

主鍵索引:加速查詢 + 列值唯一 + 表中只有乙個(不可以有null)

組合索引:多列值組成乙個索引,專門用於組合搜尋,其效率大於索引合併

全文索引:對文字的內容進行分詞,進行搜尋

建立表+索引:

create table 表名(

nid int not null auto_increment primary key,

name varchar(32) not null,

email varchar(64) not null,

extra text,

index 索引名 (欄位名)

建立索引

create index 索引名 on 表名(欄位名)

刪除索引:

drop 索引名 on 表名;

檢視索引

show index from 表名

修改資料庫root密碼:

mysql> set password for 使用者名稱@localhost = password('新密碼');

mysqladmin -u使用者名稱 -p舊密碼 password 新密碼

許可權建立使用者(授權)

grant 許可權 on 資料庫.表 to '使用者名稱'@'登入主機' [indentified by 『使用者密碼』];

撤銷許可權

remove 許可權 on 資料庫.表 from '使用者名稱'@'登入主機;

檢視許可權:

show grants;//自己

show grants for 使用者名稱@主機名稱;

資料庫mysql軟體安裝 資料庫軟體mysql安裝

2.解壓至欲安裝的目錄下 3.開啟cmd,進入軟體目錄下d qmdownload mysql 5.7.24 winx64 bin,執行mysqld 4.初始化使用者 cmd d qmdownload mysql 5.7.24 winx64 bin,執行mysqld initialize insecu...

mysql資料庫之python鏈結mysql

使用之前請在命令列pip install pymysql import pymysql 1.建立鏈結 conn pymysql.connect host 127.0.0.1 ip位址 port 3306,埠號 database database name 資料庫名稱 user mysql usern...

建立mysql資料庫

登陸資料庫 如何建立乙個資料庫和表單 new mysql.php 獲取連線mysql connect 伺服器,使用者名稱,密碼 con mysql connect localhost root if con 建立乙個資料庫school if mysql query create database s...