查看linux mysql 账户权限设置_Linux下mysql新建账号及权限设置各种方式总结
來自:http://justcoding.iteye.com/blog/1941116
1、權(quán)限賦予
說明:mysql部署在服務(wù)器A上,內(nèi)網(wǎng)上主機(jī)B通過客戶端工具連接服務(wù)器A以進(jìn)行數(shù)據(jù)庫操作,需要服務(wù)器A賦予主機(jī)B操作mysql的權(quán)限
mysql服務(wù)的啟動(dòng)和停止
net stop mysql
net start mysql
1.1 在服務(wù)器A上進(jìn)入mysql,假設(shè)在服務(wù)器A上mysql的賬戶是root:
mysql?-u?root?-p
然后回車鍵入密碼!
1.2 賦予主機(jī)B操作數(shù)據(jù)庫的權(quán)限
mysql>?grant?usage?on?*.*?to?username@192.168.0.1?identified?by?'password';
說明:賦予username@192.168.0.1?使用所有數(shù)據(jù)庫的權(quán)限,在主機(jī)192.168.0.1上使用username賬戶登錄,密碼為:password
mysql>?grant?usage?on?*.*?to?username?identified?by?'password';
說明:賦予username使用所有數(shù)據(jù)庫的權(quán)限,在所有主機(jī)上使用username賬戶登錄,密碼為:password
mysql>?grant?all?privileges?on?newdb.*?to?username@192.168.0.1;
說明:賦予username@192.168.0.1 操作數(shù)據(jù)庫newdb的最高權(quán)限,在主機(jī)192.168.0.1上使用username賬戶登錄,無密碼
mysql>?grant?all?privileges?on?*.*?to?root@192.168.0.1?identified?by?'123456'?;
說明:賦予root@192.168.0.1?使用所有數(shù)據(jù)庫的權(quán)限,在主機(jī)192.168.0.1上使用root賬戶登錄,密碼為:123456
2、移除賬號(hào)
mysql>?drop?user?root@192.168.0.1;
說明:移除賬戶root,這樣,主機(jī)192.168.0.1就不再可以使用root用戶操作服務(wù)器A上的數(shù)據(jù)庫
來源:http://www.cnblogs.com/eczhou/archive/2012/07/12/2588187.html
mysql中授權(quán)命令grant用法詳解
mysql中授權(quán)命令grant用法詳解:
mysql中可以給你一個(gè)用戶授予如select,insert,update,delete等其中的一個(gè)或者多個(gè)權(quán)限,主要使用grant命令,用法格式為:?grant 權(quán)限 on 數(shù)據(jù)庫對象 to 用戶
一、grant 普通數(shù)據(jù)用戶,查詢、插入、更新、刪除 數(shù)據(jù)庫中所有表數(shù)據(jù)的權(quán)利。
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 數(shù)據(jù)庫開發(fā)人員,創(chuàng)建表、索引、視圖、存儲(chǔ)過程、函數(shù)。。。等權(quán)限。
1. grant 創(chuàng)建、修改、刪除 MySQL 數(shù)據(jù)表結(jié)構(gòu)權(quán)限。
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.%’;
2. grant 操作 MySQL 外鍵權(quán)限。
grant references on testdb.* to developer@’192.168.0.%’;
3. grant 操作 MySQL 臨時(shí)表權(quán)限。
grant create temporary tables on testdb.* to developer@’192.168.0.%’;
4. grant 操作 MySQL 索引權(quán)限。
grant index on testdb.* to developer@’192.168.0.%’;
5. grant 操作 MySQL 視圖、查看視圖源代碼 權(quán)限。
grant create view on testdb.* to developer@’192.168.0.%’;grant show view on testdb.* to developer@’192.168.0.%’;
6. grant 操作 MySQL 存儲(chǔ)過程、函數(shù) 權(quán)限。
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 管理某個(gè) MySQL 數(shù)據(jù)庫的權(quán)限。
grant all privileges on testdb to dba@’localhost’
其中,關(guān)鍵字 “privileges” 可以省略。
四、grant 高級(jí) DBA 管理 MySQL 中所有數(shù)據(jù)庫的權(quán)限。
grant all on *.* to dba@’localhost’
五、MySQL grant 權(quán)限,分別可以作用在多個(gè)層次上。
1. grant 作用在整個(gè) MySQL 服務(wù)器上:
grant select on *.* to dba@localhost; --dba 可以查詢 MySQL 中所有數(shù)據(jù)庫中的表。
grant all on *.* to dba@localhost; --dba 可以管理 MySQL 中的所有數(shù)據(jù)庫
2. grant 作用在單個(gè)數(shù)據(jù)庫上:
grant select on testdb.* to dba@localhost; --dba 可以查詢 testdb 中的表。
3. grant 作用在單個(gè)數(shù)據(jù)表上:
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 作用在存儲(chǔ)過程、函數(shù)上:
grant execute on procedure testdb.pr_add to’dba’@’localhost’grant execute on function testdb.fn_add to ’dba’@’localhost’
六、查看 MySQL 用戶權(quán)限
查看所有當(dāng)前用戶
select * from mysql.user;
也可以進(jìn)入到mysql,切換數(shù)據(jù)庫到mysql下,使用:use mysql;
然后就可以查看了,在這里保存了一張表user,里面保存的是用戶信息,使用:
select * from user;
SELECT DISTINCT CONCAT('User:''',user,'''@''',host,''';') AS query FROM mysql.user; //這樣查看比較方便
或者只查看Ip和用戶名
select Host,User from user;
1. 查看當(dāng)前用戶(自己)權(quán)限:
show grants;
2. 查看其他 MySQL 用戶權(quán)限:
show grants for dba@localhost;
七、撤銷已經(jīng)賦予給 MySQL 用戶權(quán)限的權(quán)限。
revoke 跟 grant 的語法差不多,只需要把關(guān)鍵字 “to” 換成 “from” 即可:
grant all on *.* to dba@localhost;revoke all on *.* from dba@localhost;
八、MySQL grant、revoke 用戶權(quán)限注意事項(xiàng)
1. grant, revoke 用戶權(quán)限后,該用戶只有重新連接 MySQL 數(shù)據(jù)庫,權(quán)限才能生效。
2. 如果想讓授權(quán)的用戶,也可以將這些權(quán)限 grant 給其他用戶,需要選項(xiàng) “grant option“
grant select on testdb.* to dba@localhost with grant option;
這個(gè)特性一般用不到。實(shí)際中,數(shù)據(jù)庫權(quán)限最好由 DBA 來統(tǒng)一管理。
************************************************************
1,Mysql下創(chuàng)建新的用戶
方式一:
1.create user 用戶名 identified by '密碼';
例:
create user xiaogang identified by '123456';
新創(chuàng)建的用戶,默認(rèn)情況下是沒有任何權(quán)限的。
或者
新建普通用戶
CREATE USER 'jeffrey'@'localhost' identified BY 'mypass';
用戶名部分為“jeffrey”,主機(jī)名默認(rèn)為“%”(即對所有主機(jī)開放權(quán)限)
如果指定用戶登錄不需要密碼,則可以省略identified BY部分
方式二:
//創(chuàng)建用戶
mysql> insert into mysql.user(Host,User,Password) values(‘localhost’,'jeecn’,password(‘jeecn’));
//刷新系統(tǒng)權(quán)限表
mysql>flush privileges;
這樣就創(chuàng)建了一個(gè)名為:jeecn? 密碼為:jeecn? 的用戶。
2. 如何給用戶分配權(quán)限
語法:
1.grant 權(quán)限 on?數(shù)據(jù)庫.數(shù)據(jù)表 to '用戶' @ '主機(jī)名';
例:給 xiaogang 分配所有的權(quán)限
grant all on *.* to 'xiaogang'@'%';
這個(gè)時(shí)候 xiaogang 就擁有了 所有權(quán)限了
3 如何更精準(zhǔn)的控制用戶的權(quán)限呢?
1.grant 權(quán)限 on?數(shù)據(jù)庫.數(shù)據(jù)表 to '用戶' @ '主機(jī)名';
例:讓 xiaogang 有查詢 tmp 數(shù)據(jù)庫 tmp1 表的權(quán)限;
grant select on temp.temp1 to 'xiaogang'@'%'; //這個(gè)時(shí)候 xiaogang 就具有查詢temp小的temp1的權(quán)限了。
************************************************************
mysql授權(quán)表共有5個(gè)表:user、db、host、tables_priv和columns_priv。
授權(quán)表的內(nèi)容有如下用途:
user表
user表列出可以連接服務(wù)器的用戶及其口令,并且它指定他們有哪種全局(超級(jí)用戶)權(quán)限。在user表啟用的任何權(quán)限均是全局權(quán)限,并適用于所有數(shù)據(jù)庫。例如,如果你啟用了DELETE權(quán)限,在這里列出的用戶可以從任何表中刪除記錄,所以在你這樣做之前要認(rèn)真考慮。
db表
db表列出數(shù)據(jù)庫,而用戶有權(quán)限訪問它們。在這里指定的權(quán)限適用于一個(gè)數(shù)據(jù)庫中的所有表。
host表
host表與db表結(jié)合使用在一個(gè)較好層次上控制特定主機(jī)對數(shù)據(jù)庫的訪問權(quán)限,這可能比單獨(dú)使用db好些。這個(gè)表不受GRANT和REVOKE語句的影響,所以,你可能發(fā)覺你根本不是用它。
tables_priv表
tables_priv表指定表級(jí)權(quán)限,在這里指定的一個(gè)權(quán)限適用于一個(gè)表的所有列。
columns_priv表
columns_priv表指定列級(jí)權(quán)限。這里指定的權(quán)限適用于一個(gè)表的特定列。
刪除用戶
@>mysql -u root -p
@>密碼
mysql>Delete FROM user Where User='test' and Host='localhost';
mysql>flush privileges;
mysql>drop database testDB; //刪除用戶的數(shù)據(jù)庫
刪除賬戶及權(quán)限:>drop user 用戶名@'%';
>drop user 用戶名@?localhost;
設(shè)置最大連接數(shù)
因?yàn)轫?xiàng)目組連接數(shù)據(jù)庫總是報(bào)連接數(shù)太多,所以需要把連接數(shù)改大。
顯示當(dāng)前運(yùn)行的Query:mysql> show processlist
通常,mysql的最大連接數(shù)默認(rèn)是100, 最大可以達(dá)到16384。
1、查看最大連接數(shù):
show variables like '%max_connections%';
2、修改最大連接數(shù)
方法一:修改配置文件。推薦方法一
進(jìn)入MySQL安裝目錄 打開MySQL配置文件 my.ini(Windows下) 或 my.cnf查找 max_connections=100 修改或添加為 max_connections=1000 服務(wù)里重起MySQL即可.
修改連接數(shù):
[root@localhost ~]#?vi /etc/my.cnf
在[mysqld]中加入:
set-variable=max_connections=1000
目錄在etc下面
方法二:命令行修改。不推薦方法二
命令行登錄MySQL后。設(shè)置新的MySQL最大連接數(shù)為1024:
MySQL> set global max_connections=1024;
這種方式有個(gè)問題,就是設(shè)置的最大連接數(shù)只在mysql當(dāng)前服務(wù)進(jìn)程有效,一旦mysql重啟,又會(huì)恢復(fù)到初始狀態(tài)。因?yàn)閙ysql啟動(dòng)后的初始化工作是從其配置文件中讀取數(shù)據(jù)的,而這種方式?jīng)]有對其配置文件做更改。
linux下如何啟動(dòng)/停止/重啟mysql:
啟動(dòng):service mysqld start
停止:service mysqld stop
重啟:service mysqld restart
總結(jié)
以上是生活随笔為你收集整理的查看linux mysql 账户权限设置_Linux下mysql新建账号及权限设置各种方式总结的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 内存管理vma_(十三)Linux内存管
- 下一篇: centos mysql 端口_Linu