Showing posts with label use test. Show all posts
Showing posts with label use test. Show all posts

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 >

Tuesday, 13 December 2011

MySQL BLACKHOLE Engine (again)

My previous post about this was run on a MySQL installation on UNIX. I decided to have another go using the MySQL on my home PC, which is installed on Windows XP. First I had a look for the have_blackhole_engine variable but I could not find it:
  
mysql> SHOW VARIABLES LIKE 'have_blackhole_engine';
Empty set (0.00 sec)

mysql>


But I decided to carry on and created a table using the BLACKHOLE engine:

mysql> use test
Database changed
mysql> create table andrew (col1 varchar(10));
Query OK, 0 rows affected (0.41 sec)

mysql> alter table andrew engine = blackhole;
Query OK, 0 rows affected (0.17 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>

Then I inserted a row into the table and looked for it but it had gone so this time it had worked as expected:

mysql> insert into andrew values ('Fred');
Query OK, 1 row affected (0.00 sec)

mysql> select * from andrew;
Empty set (0.00 sec)

mysql>