MySQL新增使用者、刪除使用者與授權
1.新建使用者
1.1 登入MYSQL:
@>mysql -u root -p
@>密碼
1.2 建立使用者:
mysql> insert into mysql.user(Host,User,Password) values("localhost","test",password("1234"));
這樣就建立了一個名為:test 密碼為:1234 的使用者。
注意:此處的"localhost",是指該使用者只能在本地登入,不能在另外一臺機器上遠端登入。如果想遠端登入的話,將"localhost"改為"%",表示在任何一臺電腦上都可以登入。也可以指定某臺機器可以遠端登入。
1.3 然後登入一下:
mysql>exit;
@>mysql -u test -p
@>輸入密碼
mysql>登入成功
2.為使用者授權
授權格式:grant 許可權 on 資料庫.* to 使用者名稱@登入主機 identified by "密碼";
2.1 登入MYSQL(有ROOT許可權),這裡以ROOT身份登入:
@>mysql -u root -p
@>密碼
2.2 首先為使用者建立一個數據庫(testDB):
mysql>create database testDB;
2.3 授權test使用者擁有testDB資料庫的所有許可權(某個資料庫的所有許可權):
mysql>grant all privileges on testDB.* to [email protected] identified by '1234';
mysql>flush privileges;//刷新系統許可權表
格式:grant 許可權 on 資料庫.* to 使用者名稱@登入主機 identified by "密碼";
2.4 如果想指定部分許可權給一使用者,可以這樣來寫:
mysql>grant select,update on testDB.* to [email protected] identified by '1234';
mysql>flush privileges; //刷新系統許可權表
2.5 授權test使用者擁有所有資料庫的某些許可權:
mysql>grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";
//test使用者對所有資料庫都有select,delete,update,create,drop 許可權。
//@"%" 表示對所有非本地主機授權,不包括localhost。(localhost地址設為127.0.0.1,如果設為真實的本地地址,不知道是否可以,沒有驗證。)
//對localhost授權:加上一句grant all privileges on testDB.* to [email protected] identified by '1234';即可。
3. 刪除使用者
@>mysql -u root -p
@>密碼
mysql>Delete FROM user Where User='test' and Host='localhost';
mysql>flush privileges;
mysql>drop database testDB; //刪除使用者的資料庫
刪除賬戶及許可權:>drop user 使用者名稱@'%';
>drop user 使用者名稱@ localhost;
4. 修改指定使用者密碼
@>mysql -u root -p
@>密碼
mysql>update mysql.user set password=password('新密碼') where User="test" and Host="localhost";
mysql>flush privileges;
使用者管理 mysql>use mysql; 檢視 mysql> select host,user,password from user ; 建立 mysql> create user zx_root IDENTIFIED by 'xxxxx'; //identified by 會將純文字密碼加密作為雜湊值儲存 修改 mysql>rename user feng to newuser;//mysql 5之後可以使用,之前需要使用update 更新user表 刪除 mysql>drop user newuser; //mysql5之前刪除使用者時必須先使用revoke 刪除使用者許可權,然後刪除使用者,mysql5之後drop 命令可以刪除使用者的同時刪除使用者的相關許可權 更改密碼 mysql> set password for zx_root =password('xxxxxx'); mysql> update mysql.user set password=password('xxxx') where user='otheruser' 檢視使用者許可權 mysql> show grants for zx_root; 賦予許可權 mysql> grant select on dmc_db.* to zx_root; 回收許可權 mysql> revoke select on dmc_db.* from zx_root; //如果許可權不存在會報錯 上面的命令也可使用多個許可權同時賦予和回收,許可權之間使用逗號分隔 mysql> grant select,update,delete ,insert on dmc_db.* to zx_root; 如果想立即看到結果使用 flush privileges ; 命令更新 設定許可權時必須給出一下資訊 1,要授予的許可權 2,被授予訪問許可權的資料庫或表 3,使用者名稱 grant和revoke可以在幾個層次上控制訪問許可權 1,整個伺服器,使用 grant ALL 和revoke ALL 2,整個資料庫,使用on database.* 3,特點表,使用on database.table 4,特定的列 5,特定的儲存過程 user表中host列的值的意義 % 匹配所有主機 localhost localhost不會被解析成IP地址,直接通過UNIXsocket連線 127.0.0.1 會通過TCP/IP協議連線,並且只能在本機訪問; ::1 ::1就是相容支援ipv6的,表示同ipv4的127.0.0.1grant 普通資料使用者,查詢、插入、更新、刪除 資料庫中所有表資料的權利。
grant select on testdb.* to [email protected]’%’
grant insert on testdb.* to [email protected]’%’
grant update on testdb.* to [email protected]’%’
grant delete on testdb.* to [email protected]’%’
或者,用一條 MySQL 命令來替代:
grant select, insert, update, delete on testdb.* to [email protected]’%’
9>.grant 資料庫開發人員,建立表、索引、檢視、儲存過程、函式。。。等許可權。
grant 建立、修改、刪除 MySQL 資料表結構許可權。
grant create on testdb.* to [email protected]’192.168.0.%’;
grant alter on testdb.* to [email protected]’192.168.0.%’;
grant drop on testdb.* to [email protected]’192.168.0.%’;
grant 操作 MySQL 外來鍵許可權。
grant references on testdb.* to [email protected]’192.168.0.%’;
grant 操作 MySQL 臨時表許可權。
grant create temporary tables on testdb.* to [email protected]’192.168.0.%’;
grant 操作 MySQL 索引許可權。
grant index on testdb.* to [email protected]’192.168.0.%’;
grant 操作 MySQL 檢視、檢視檢視原始碼 許可權。
grant create view on testdb.* to [email protected]’192.168.0.%’;
grant show view on testdb.* to [email protected]’192.168.0.%’;
grant 操作 MySQL 儲存過程、函式 許可權。
grant create routine on testdb.* to [email protected]’192.168.0.%’; -- now, can show procedure status
grant alter routine on testdb.* to [email protected]’192.168.0.%’; -- now, you can drop a procedure
grant execute on testdb.* to [email protected]’192.168.0.%’;
10>.grant 普通 DBA 管理某個 MySQL 資料庫的許可權。
grant all privileges on testdb to [email protected]’localhost’
其中,關鍵字 “privileges” 可以省略。
11>.grant 高階 DBA 管理 MySQL 中所有資料庫的許可權。
grant all on *.* to [email protected]’localhost’
12>.MySQL grant 許可權,分別可以作用在多個層次上。
1. grant 作用在整個 MySQL 伺服器上:
grant select on *.* to [email protected]; -- dba 可以查詢 MySQL 中所有資料庫中的表。
grant all on *.* to [email protected]; -- dba 可以管理 MySQL 中的所有資料庫
2. grant 作用在單個數據庫上:
grant select on testdb.* to [email protected]; -- dba 可以查詢 testdb 中的表。
3. grant 作用在單個數據表上:
grant select, insert, update, delete on testdb.orders to [email protected];
4. grant 作用在表中的列上:
grant select(id, se, rank) on testdb.apache_log to [email protected];
5. grant 作用在儲存過程、函式上:
grant execute on procedure testdb.pr_add to ’dba’@’localhost’
grant execute on function testdb.fn_add to ’dba’@’localhost’
注意:修改完許可權以後 一定要重新整理服務,或者重啟服務,重新整理服務用:FLUSH PRIVILEGES。 許可權表許可權 | 說明 |
all | |
alter | |
alter routine | 使用alter procedure 和drop procedure |
create | |
create routine | 使用create procedure |
create temporary tables | 使用create temporary table |
create user | |
create view | |
delete | |
drop | |
execute | 使用call和儲存過程 |
file | 使用select into outfile 和load data infile |
grant option | 可以使用grant和revoke |
index | 可以使用create index 和drop index |
insert | |
lock tables | 鎖表 |
process | 使用show full processlist |
reload | 使用flush |
replication client | 伺服器位置訪問 |
replocation slave | 由複製從屬使用 |
select | |
show databases | |
show view |
shutdown | 使用mysqladmin shutdown 來關閉mysql |
super | |
update | |
usage | 無訪問許可權 |
相關推薦
MySQL新增使用者、刪除使用者與授權
ySql中新增使用者,新建資料庫,使用者授權,刪除使用者,修改密碼(注意每行後邊都跟個;表示一個命令語句結束): 1.新建使用者 1.1 登入MYSQL: @>mysql -u root -p @>密碼 1.2 建立使用者: mysql>
MySQL && MySQL密碼修改、新增使用者、刪除使用者與授權
密碼管理 修改已知原密碼 方法1: 用SET PASSWORD命令 首先登入MySQL。 set password for root@localhost = password('123');
(mysql筆記)新增使用者、刪除使用者與授權
新增使用者、刪除使用者與授權 連線資料庫 mysql -uroot -proot MySQL5.7 mysql.user表沒有password欄位改 authentication_string; 一. 建立使用者: 命令:CREATE USER ‘username’@
MySQL5.7 啟動、新增使用者、刪除使用者與授權
參考: https://www.cnblogs.com/xujishou/p/6306765.html MySQL5.7 mysql.user表沒有password欄位改 authentication_string; 零. 啟動mysql 啟動mysql: 在 計算機→管理→服務
MySQL5.7 新增使用者、刪除使用者與授權
mysql -uroot -proot MySQL5.7 mysql.user表沒有password欄位改 authentication_string; 一. 建立使用者: 命令:CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 例子: CREAT
MySQL5.7 新增使用者、刪除使用者與授權,建立、刪除、切換資料庫
建立使用者:create user 'test'@'localhost' identified by 'michael123';test: 使用者名稱michael123: 密碼localhost: 只有本機可以訪問create user 'michael'@'%' iden
mysql建立、刪除使用者與授權(linux測試)
注:我的執行環境是SUSE Linux + mysql5.6 一.建立使用者: 命令:CREATE USER 'username'@'host' IDENTIFIED BY 'password';
MYSQL建立使用者、刪除使用者、使用者授權、修改密碼
建立使用者: 1、使用win+r開啟命令視窗 2、執行命令:CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 3、查詢使用者:使用‘select user,user.password form mysql.us
Unity/C#基礎複習(5) 之 淺析觀察者、中介者模式在遊戲中的應用與delegate原理
參考資料 【1】 《Unity 3D指令碼程式設計 使用C#語言開發跨平臺遊戲》陳嘉棟著 【2】 @張子陽【C#中的委託和事件 - Part.1】 http://www.tracefact.net/tech/009.html 【3】 @張子陽【C#中的委託和事件 - Part.2】 http://www.t
linux mysql添加、刪除用戶、用戶權限及mysql最大字段數量
cat eight use 刪除數據庫 pda 主機 ide from 多個 1. 登錄: mysql -u username -p 顯示全部的數據庫: show databases; 使用某一個數據庫: use databasename; 顯示一個數據庫的全
MySql 清空、刪除表時 1701錯誤
專案已經進行一段時間,整體的開發工作已經完成。接下來要進入綜合測試階段,所以想要將資料清理一下,然後報了1701錯誤,由錯誤提示得知是外來鍵約束的問題 解決辦法: 一、先刪除外來鍵…不過多贅述 二、先取消外來鍵約束,刪除後再新增約束 SET foreign_key_chec
Oracle 新增列、刪除列
--新增一列 ALTER TABLE table_name ADD column_1 DATE NOT NULL; ALTER TABLE table_name ADD column_2 VARCHAR2(44) DEFAULT ''; ALTER TABLE table_name ADD co
js動態給表格新增一行、刪除一行
最近寫程式碼遇到這個需求,特地總結了一下寫了個demo,如下所示: 程式碼: <!DOCTYPE html> <html> <head> <title>new document</title> <meta http-
mysql 等值連線、自然連線與笛卡爾積
1.等值連線(where子句中使用=等號為限定條件) SELECT * FROM runoob_tb a, tcount_tb b WHERE a.runoob_author = b.runoob_author; 2. 自然連線 NATURAL JOIN (自然連線只考慮屬
MySQL 新增索引,刪除索引及其用法
一.索引的作用 一般的應用系統,讀寫比例在10:1左右,而且插入操作和一般的更新操作很少出現效能問題,遇到最多的,也是最容易出問題的,還是一些複雜的查詢操作,所以查詢語句的優化顯然是重中之重。 在資料量和訪問量不大的情況下,mysql訪問是非常
Js新增元素、刪除元素誤區詳解【push()和add();splice()和remove()】
新增元素之誤區一,push()和add()使用及區別 push()方法是給陣列尾巴新增一個或多個元素,返回的是新增陣列後該陣列長度。 測試程式碼: var arr = [1,2,3,4]; var arrlength = arr.push(5); console.log("arr
redis-cluster叢集新增節點、刪除節點
1.新增節點 1.1:重新搭建叢集 之前安裝的叢集有三個節點,每個節點有一備份節點。為了方便測試,將之前的每個redis節點下的dump.rdb 和nodes.conf刪掉,重新搭建一個只有三個master的叢集(7001,7002,7003) 重新啟動三個master
MySQL新增使用者、為使用者分配許可權
登入MySQL 登入本地使用者 mysql -u root -p 登入外網使用者(需要注意伺服器可能只允許本地登入,需要修改響應的配置檔案) mysql -u zhrt -h 10.64.6.4 -p 新增使用者 1.允許本地訪問的使用者(127.0
Linux mysql新增使用者,刪除使用者,以及使用者許可權
荊軻刺秦王 一些主要命令: 登陸: mysql -u username -p 一般都是:mysql -u root -p 也可以:mysql
mysql資料庫建立、刪除資料庫
一、建立資料庫(預設字符集和排序規則) (1)建立資料庫 mysql> CREATE DATABASE my_db1; Query OK, 1 row affected (0.00 sec