首頁  >  文章  >  後端開發  >  linux php連線mysql權限不夠怎麼辦

linux php連線mysql權限不夠怎麼辦

藏色散人
藏色散人原創
2021-10-26 10:01:192420瀏覽

linux php連接mysql權限不夠的解決方法:1、透過使用grant指令給予一般資料使用者查詢,插入等權限;2、透過grant給資料庫開發人員授予建立資料表和索引等權限即可。

linux php連線mysql權限不夠怎麼辦

本文操作環境:linux5.9.8系統、PHP7.1版、DELL G3電腦

#linux php連線mysql權限不夠怎麼辦?

linux php連接mysql權限不夠,mysql精細權限劃分:

mysql中可以給你一個用戶授予如select,insert,update,delete等其中的一個或多個權限,主要使用grant指令,用法格式為:

grant 权限 on 数据库对象 to 用户

一、grant 普通資料用戶,查詢、插入、更新、刪除資料庫中所有表格資料的權利

grant select on testdb.* to common_user@’%’
grant insert on testdb.* to common_user@’%’
grant update on testdb.* to common_user@’%’
grant delete on testdb.* to common_user@’%’

或者,用一條mysql 指令來取代:

grant select, insert, update, delete on testdb.* to common_user@’%’

二、grant 資料庫開發人員,建立表格、索引、檢視、預存程序、函數。 。 。等權限

grant 创建、修改、删除 mysql 数据表结构权限。
grant create on testdb.* to developer@’192.168.0.%’;
grant alter on testdb.* to developer@’192.168.0.%’;
grant drop on testdb.* to developer@’192.168.0.%’;
grant 操作 mysql 外键权限。
grant references on testdb.* to developer@’192.168.0.%’;
grant 操作 mysql 临时表权限。
grant create temporary tables on testdb.* to developer@’192.168.0.%’;
grant 操作 mysql 索引权限。
grant index on testdb.* to developer@’192.168.0.%’;
grant 操作 mysql 视图、查看视图源代码 权限。
grant create view on testdb.* to developer@’192.168.0.%’;
grant show view on testdb.* to developer@’192.168.0.%’;
grant 操作 mysql 存储过程、函数 权限。
grant create routine on testdb.* to developer@’192.168.0.%’; - now, can show procedure status
grant alter routine on testdb.* to developer@’192.168.0.%’; - now, you can drop a procedure
grant execute on testdb.* to developer@’192.168.0.%’;

三、grant 普通 dba 管理某個 mysql 資料庫的權限

grant all privileges on testdb to dba@’localhost’

其中,關鍵字 “privileges” 可以省略。

四、grant 高級dba 管理mysql 中所有資料庫的權限

grant all on *.* to dba@’localhost’

五、mysql grant 權限,分別可以作用在多個層次上

1. grant 作用在整個mysql 伺服器上:

grant select on *.* to dba@localhost; - dba 可以查询 mysql 中所有数据库中的表。
grant all on *.* to dba@localhost; - dba 可以管理 mysql 中的所有数据库

2. grant 作用在單一資料庫上:

grant select on testdb.* to dba@localhost; - dba 可以查询 testdb 中的表。

3. grant 作用在單一資料表上:

grant select, insert, update, delete on testdb.orders to dba@localhost;

4. grant 作用在表中的列上:

grant select(id, se, rank) on testdb.apache_log to dba@localhost;

5. grant 作用在預存程序、函數上:

grant execute on procedure testdb.pr_add to ’dba’@’localhost’
grant execute on function testdb.fn_add to ’dba’@’localhost’

六、查看mysql 使用者權限

查看目前使用者(自己)權限:

show grants;

查看其他mysql 使用者權限:

show grants for dba@localhost;

七、撤銷已經賦予給mysql 使用者權限的權限

revoke 跟grant 的語法差不多,只要把關鍵字「to」 換成「from」即可:

grant all on *.* to dba@localhost;
revoke all on *.* from dba@localhost;

八、mysql grant、revoke 使用者權限注意事項

1. grant, revoke 使用者權限後,該使用者只有重新連接mysql 資料庫,權限才能生效。

2. 如果想要授權的用戶,也可以將這些權限 grant 給其他用戶,需要選項 「grant option「

grant select on testdb.* to dba@localhost with grant option;

這個特性一般用不到。實際上中,資料庫權限最好由 dba 來統一管理。

注意:修改完權限以後 一定要刷新服務,或重新啟動服務

推薦學習:《PHP影片教學

以上是linux php連線mysql權限不夠怎麼辦的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn