MySQL資料庫授權的兩種方式

2021-09-21 04:50:15 字數 1833 閱讀 3893

mysql資料庫授權的兩種方式

方法一:通過grant命令建立使用者並授權

grant命令簡單語法如下:

grant all privileges on dbname.* to username@localhost identified by 'passwd';

列表說明如下:

說明:上述命令是授權localhost主機上通過使用者username管理dbname資料庫的所有許可權,密碼是passwd。其中,username,dbname,passwd可根據業務的情況修改。

舉例:建立zd使用者,對test庫具備所有許可權,允許從localhost主機登陸管理資料庫,密碼為123456。

首先,檢視下當前資料庫使用者情況:

最後,檢視當前資料庫使用者情況:

檢視授權使用者具體許可權:

mysql> show grants for zd@localhost;(或者mysql> show grants for zd@localhost\g)

說明:可以看到預設許可權是usage,即連線許可權,後面又增加了all許可權!

方法二:create和grant配合法

首先建立使用者username及密碼passwd,授權主機localhost。

語法:create user username@localhost identified by 'passwd';

如:建立使用者www及密碼123456,授權主機localhost。

mysql> create user www@localhost identified by '123456';

然後授權localhost主機上通過使用者username管理dbname資料庫的所有許可權,無需密碼。

語法:grant all on dbname.* to username@localhost;

如:授權localhost主機上www管理test資料庫的所有許可權。

mysql> grant all on test.* to zd@localhost;

檢視當前使用者資訊:

檢視www具體許可權:

mysql> show grants for www@localhost;(或者mysql> show grants for www@localhost\g)

shell操作mysql資料庫的兩種方式

最近在學習linux和指令碼程式設計,感覺指令碼語言在很多時候真的很方便,比如 伺服器監控 日誌分析及統計 自動化管理等等。shell操作mysql資料庫,記錄一下 第一種方式 bin sh mysql uroot insert into nihao.test name,password value...

資料庫兩種驗證鏈結方式

第一種 server 伺服器名稱 資料庫的例項名 uid 登入名 pwd 密碼 database 資料庫名稱 第二種 data source 伺服器名稱 資料庫例項名 initial catalog 資料庫名稱 user id 使用者名稱 password 密碼 以 windows 身份驗證方式登入...

php mysqli資料庫連線的兩種方式

這裡講述mysqli資料庫連線兩種方式比較,即物件導向與面向過程。如下 第一種方式 物件導向的方式建立資料庫連線 複製 如下 mysqli new mysqli localhost root 1233456 預設的 mysql的類,其屬性與方法見手冊 if mysqli connect error ...