Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grant file on just one database

Tags:

mysql

I want to allow LOAD DATA command for the john mysql user. So I logged into mysql terminal as root and issued the following statement:

grant file on johndatabase.* to 'john'@'localhost'; 

But I got the following error:

ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES 

If I replaced johndatabase.* with *.*, then everything works. But doesn't *.* mean all databases? I want to limit the john mysql user to just johndatabase.

like image 390
John Avatar asked Nov 25 '12 15:11

John


People also ask

How do you grant permissions to a database?

To GRANT ALL privileges to a user , allowing that user full control over a specific database , use the following syntax: mysql> GRANT ALL PRIVILEGES ON database_name. * TO 'username'@'localhost';

How do I enable file privileges in MySQL?

mysql> GRANT INSERT(user) ON mysql. user TO 'user'@'hostname'; This will ensure that the user can't change any privilege columns directly, but has to use the GRANT command to give privileges to other users. This option causes the server not to use the privilege system at all.

What is database grant?

Database Grants. Database permissions are defined on the database as a whole. They set a number of limits that affect the authorization identifiers (that is, groups, roles, users, or public) specified when the grant is defined.

How do I make my MySQL database read only?

At the mysql prompt, do one of the following steps: To give the user access to the database from any host, type the following command: grant select on database_name. * to 'read-only_user_name'@'%' identified by 'password';


1 Answers

You can't grant FILE privileges on just a single database. That logically doesn't make any sense. Consider what the docs say:

The FILE privilege gives you permission to read and write files on the server host using the LOAD DATA INFILE and SELECT ... INTO OUTFILE statements and the LOAD_FILE() function. A user who has the FILE privilege can read any file on the server host that is either world-readable or readable by the MySQL server. (This implies the user can read any file in any database directory, because the server can access any of those files.)

Thus, the FILE privilege is a global privilege. It affects all files on the server and allows access only to global commands (e.g. LOAD DATA INFILE, etc...), not scoped to any database. The only way to grant FILE privileges is on all databases, using this syntax:

GRANT FILE ON *.* TO 'john'@'localhost'; 
like image 150
Ben Lee Avatar answered Sep 23 '22 13:09

Ben Lee