天天看點

MySQL 使用者和權限管理伺服器端配置使用者軟體安裝目錄資料路徑socket檔案位置伺服器id号短口号用戶端配置socket檔案位置授權TCPIPSocket

使用者和權限管理

使用者作用

登入mysql

管理mysql

使用者定義

使用者名@'白名單'

寫法:

wordpress@'%'

wordpress@'localhost'

wordpress@'127.0.0.1'

wordpress@'10.0.0.%'

wordpress@'10.0.0.5%'

wordpress@'10.0.0.0/255.255.254.0'

wordpress@'10.0.%'

使用者管理

建立使用者

mysql> create user ac@'10.0.0.%' identified by 'sa';

說明:8.0以前,可以自動建立使用者并授權

mysql> grant all on . to ac@'10.0.0.%' identified by 'sa';

查詢使用者

mysql> select user,host from mysql.user;

修改使用者密碼

mysql> alter user ac@'10.0.0.%' identified by 'sa';

删除使用者

mysql> drop user ac@'10.0.0.%' ;

權限管理

權限清單

ALL

SELECT,INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE

授權指令

例:grant all on . to ac@'10.0.0.%' identified by 'sa' with grant option;

說明:grant [權限] on [作用目标] to [使用者] identified by [密碼] with grant option

授權需求

建立一個管理者使用者root,可以通過10網段,管理資料庫.

grant SELECT,INSERT, UPDATE, DELETE on wordpress.* to wordpress@'10.0.0.%' identified by '123';

建立一個應用使用者wordpress,可以通過10網段,wordpress庫下的所有表進行SELECT,INSERT, UPDATE, DELETE.

權限回收

show grants for wordpress@'10.0.0.%';

mysql> revoke delete on wordpress.* from 'wordpress'@'10.0.0.%';

mysql> show grants for wordpress@'10.0.0.%';

MySQL 的啟動和關閉

正常啟停

sys -v

mysql.server start ---> mysqld_safe ---> mysqld

system

mysql.service ---> mysqld

    需要依賴于 /etc/my.cnf

維護

mysqld_safe

例:修改密碼mysqld_safe --skip-grant-tables --skip-networking &

将參數臨時加到指令行,指令行的優先級高

初始化配置

初始化作用

影響資料庫的啟動

影響到用戶端的功能

初始化方法

初始化配置檔案(例如/etc/my.cnf)

啟動指令行上進行設定(例如:mysqld_safe mysqld)

預編譯時設定(僅限于編譯安裝時設定)

配置檔案格式

[标簽]

xxx=xxx

标簽歸類

伺服器端:

[mysqld]

[mysqld_safe]

[server]

用戶端:

[mysql]

[mysqladmin]

[mysqldump]

[client]

模闆檔案 (5.7)

伺服器端配置

使用者

user=mysql

軟體安裝目錄

basedir=/application/mysql

資料路徑

datadir=/data/mysql/data

socket檔案位置

socket=/tmp/mysql.sock

伺服器id号

server_id=6

短口号

port=3306

用戶端配置

配置檔案讀取順序

查詢: mysqld --help --verbose |grep my.cnf

/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

強制使用自定義配置檔案

--defautls-file

[root@db01 tmp]# mysqld_safe --defaults-file=/tmp/aa.txt &

MySQL的連接配接管理

mysql連接配接指令

注意:提前應該将使用者授權做好

授權

mysql> grant all on . to root@'10.0.0.%' identified by '123';

TCPIP

mysql -uroot -p -h 10.0.0.51 -P3306

Socket

mysql -uroot -p -S /tmp/mysql.sock

用戶端工具

dbforger

sqlyog

navicat