mysql中FILE許可權

2022-05-08 11:42:11 字數 2416 閱讀 8241

file許可權指的是對伺服器主機上檔案的訪問,資料庫使用者擁有file許可權才可以執行select into outfile,load data infile操作。

參考文章:

測試select into outfile操作

root使用者上執行

mysql>

create

user

'filetest

'@'localhost

' identified by 『123456'

file許可權是對所有資料庫檔案而言的,因此資料庫只能寫成*.*,而不是某乙個資料庫

mysql> grant file on test3.* to

'filetest'

@'localhost'

;error 1221 (hy000): incorrect usage of db grant and global privileges

//賦予file許可權

mysql> grant file on *.* to

'filetest'

@'localhost'

;query ok, 0 rows affected (0.00 sec)

//賦予select許可權

grant select on test3.* to

'filetest'

@'localhost'

;//重新整理資訊

flush privileges;

filetest使用者上執行

use

test3;

mysql

>

select

*from test2 into outfile '

d:/test.txt

'->

;error

1290 (hy000): the mysql server is running with the --

secure-file-priv opti

on so it cannot execute

this statement

//即使有了file許可權,輸出目錄路徑應該secure_file_priv一致

mysql

> show variables like

'%sec%

'->;+

--------------------------+----------+

| variable_name | value |+--

------------------------+----------+

| require_secure_transport |

off|

| secure_auth |on|

| secure_file_priv | e:\test\ |+--

------------------------+----------+

mysql>

select

*from test2 into outfile '

e:/test/test.txt';

query ok,

1 row affected (0.01 sec)

測試load data infile操作:

mysql>

load data infile '

e:/test/test.txt

'into

table

test2;

error

1142 (42000): insert command denied to

user

'filetest

'@'localhost

'for

table

'test2'//

需要給filetest賦予insert許可權

root使用者上執行:

mysql

>

grant

insert

on test3.*to'

filetest

'@'localhost';

flush

privileges

;filetest使用者:

//infile的目錄也要與secure_file_

priv一致

mysql

>

load data infile '

e:/test/test.txt

'into

table

test2;

query ok,

1 row affected (0.07

sec)

records:

1 deleted: 0 skipped: 0 warnings: 0

MySQL中許可權管理

mysql許可權系統通過下面兩個階段進行認證 對連線的使用者進行身份認證,合法的使用者通過認證,不合法的使用者拒絕連線。對通過認證的合法使用者授予相應的許可權,使用者可以通過再這些許可權範圍內對資料庫做相應的操作。在許可權訪問過程中,主要涉及到mysql資料庫下user表和db表。user表的資料結...

linux中MySQL許可權問題

the mysql server is running with the read only option so it cannot execute this statement 檢視read only屬性,在mysql中執行 show variables like read only 如果屬性為o...

mysql 重新整理許可權 mysql許可權

1,檢視所有使用者許可權 select distinct concat user user,host,as query from mysql.user 或者 select from mysql.user 2,檢視某乙個使用者的許可權 show grants for user ip 3,分配許可權 以...