Saturday 7 January 2012

FILE Privilege

If you create a user called andrew:
 
UNIX > mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 45881
Server version: 5.0.67 Source distribution
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
mysql> create user 'andrew'@'localhost'
    -> identified by 'secret_password';
Query OK, 0 rows affected (0.00 sec)
 
mysql>
 
... and that user creates a table:
 
UNIX > mysql -u andrew -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 45883
Server version: 5.0.67 Source distribution
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
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> create table andrews_table
    -> (col1 varchar(10));
Query OK, 0 rows affected (0.01 sec)
 
mysql> insert into andrews_table
    -> values ('Noddy');
Query OK, 1 row affected (0.00 sec)
 
mysql>
 
... then tries to output its contents into a file, it fails:
 
mysql> select * from andrews_table
    -> into outfile 'contents';
ERROR 1045 (28000): Access denied for user 'andrew'@'localhost' (using password: YES)
mysql>
 
To fix this, you need to grant the file privilege to the user:
 
UNIX > mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 45889
Server version: 5.0.67 Source distribution
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
mysql> grant file on *.* to andrew@localhost;
Query OK, 0 rows affected (0.00 sec)
 
mysql>
 
... then when the user tries again it works:
 
UNIX > mysql -u andrew -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 45890
Server version: 5.0.67 Source distribution
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
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 andrews_table
    -> into outfile 'contents';
Query OK, 1 row affected (0.00 sec)
 
mysql> exit
Bye
UNIX > 
 
and produces a file like this:
 
UNIX > cat contents
Noddy
UNIX >

No comments: