MySQL新增使用者以及資料庫訪問授權,mysql新增
# mysql -u root -p# 允許本地 IP 訪問 localhost, 127.0.0.1# insert into mysql.user(Host,User,Password) values('localhost','zhouz',password('1234'));# 允許外網 IP 訪問# insert into mysql.user(Host,User,Password) values('%','zhouz',password('1234'));# 重新整理授權# flush privileges;# 建立資料庫# create database zhouzdb DEFAULT CHARSET utf8 COLLATE utf8_general_ci;# 授予使用者通過外網IP對於該資料庫的全部許可權# grant all privileges on `zhouzdb`.* to 'zhouz'@'%' identified by '1234';# 授予使用者在本機伺服器對該資料庫的全部許可權# grant all privileges on `zhouzdb`.* to 'zhouz'@'localhost' identified by '1234';# 重新整理許可權# flush privileges;# 退出 root 重新登入# \q# 已新帳號 zhouz 登入,由於使用的是 % 任意IP串連,所以需要指定外部存取IP# mysql -u zhouz -h 192.168.1.168 -p# 1234
平時難得用下 mysql 的命令列模式操作,今天弄下建立使用者授權,遇到些問題在這裡簡單整理下
注意: 若僅開放外網存取權限,則本地是無法訪問的,需要本機伺服器也能訪問 mysql 則要增加本地存取權限
MySQL怎授權一個自己的建立的使用者比如daitest建立新資料庫的權利?命令
慢慢看吧
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......餘下全文>>
MYSQL資料庫怎賦予遠程某個IP存取權限
你的MYSQL資料庫裡面有一個資料庫,名字教做mysql,裡面有個表,名字叫做user,你看一下這個表的結構和現有資料,你就知道應該怎麼做了,比如你可以添加一條資料,Host為你指定的IP,user可以是%,password就不管了,後面設定相應的許可權(可以全部都是Y),這樣那個機器無論用什麼使用者和密碼都可以串連資料庫,而擁有你指定的許可權。
耐心點吧,我相信你一看就明白。
參考資料:blog.chinaunix.net/u2/73743/showart_1094545.html