file權(quán)限指的是是否能夠?qū)ο到y(tǒng)的文件讀取和寫操作.
擁有file權(quán)限才可以執(zhí)行 select ..into outfile和load data infile…操作,
但是不要把file, process, super權(quán)限授予管理員以外的賬號(hào),這樣存在嚴(yán)重的安全隱患。 下面簡(jiǎn)單做個(gè)試驗(yàn):
1、創(chuàng)建環(huán)境
MySQL> CREATE USER 'filetest'@'localhost' IDENTIFIED BY 'mypass';
Query OK, 0 rows affected (0.01 sec)
mysql> GRANT select ON test.* TO 'filetest'@'localhost';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT select ON test.* TO 'filetest'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE TABLE tab1(
-> aa varchar(50),
-> bb varchar(50)
-> );
Query OK, 0 rows affected (0.02 sec)
mysql>
mysql> insert into tab1 values('aaa','bbb');
Query OK, 1 row affected (0.01 sec)
mysql> insert into tab1 values('ccc','ddd');
Query OK, 1 row affected (0.01 sec)
mysql>
2、切換到filetest用戶:
[root@master ~]# mysql -ufiletest -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.13-log Source distribution
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.00 sec)
mysql> select * from tab1 into outfile '/mysql/mysql57/st_file1';
ERROR 1045 (28000): Access denied for user 'filetest'@'localhost' (using password: YES)
沒有file權(quán)限,倒出報(bào)錯(cuò)!
3、root登陸授權(quán):
mysql> grant file on test.* to filetest@localhost;
ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES
mysql> grant file on *.* to filetest@localhost;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
4、filetest用戶登陸
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from tab1 into outfile '/mysql/mysql57/st_file';
Query OK, 2 rows affected (0.01 sec)
mysql>
[root@master mysql57]# cat st_file
aaa bbb
ccc ddd
5、導(dǎo)入
mysql> create table tab2 as select * from tab1;
Query OK, 2 rows affected (0.02 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> desc tab2
-> ;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| aa | varchar(50) | YES | | NULL | |
| bb | varchar(50) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.01 sec)
mysql> select * from tab2;
+------+------+
| aa | bb |
+------+------+
| aaa | bbb |
| ccc | ddd |
+------+------+
2 rows in set (0.00 sec)
mysql> truncate table tab2;
Query OK, 0 rows affected (0.02 sec)
mysql> select * from tab2;
Empty set (0.00 sec)
mysql> load data infile '/mysql/mysql57/st_file1' into table tab2;
ERROR 1142 (42000): INSERT command denied to user 'filetest'@'localhost' for table 'tab2'
##root登陸授權(quán):
mysql> grant insert on test.* to filetest@localhost;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
##重新登陸:
mysql> load data infile '/mysql/mysql57/st_file1' into table tab2;
Query OK, 2 rows affected (0.01 sec)
Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
mysql> select * from tab2;
+------+------+
| aa | bb |
+------+------+
| aaa | bbb |
| ccc | ddd |
+------+------+
2 rows in set (0.00 sec)
小實(shí)驗(yàn)完成。
本文名稱:MySQLfile權(quán)限
分享路徑:http://www.muchs.cn/article10/ihepdo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、搜索引擎優(yōu)化、網(wǎng)頁設(shè)計(jì)公司、定制開發(fā)、商城網(wǎng)站、定制網(wǎng)站
廣告
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源:
創(chuàng)新互聯(lián)