Bug #88649 Allow user to set default tablespace for CREATE TABLE
Submitted: 24 Nov 2017 22:53 Modified: 21 Oct 2020 14:15
Reporter: Colin Mollenhour Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DDL Severity:S4 (Feature request)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any
Tags: Tablespace

[24 Nov 2017 22:53] Colin Mollenhour
Description:
The new tablespace changes are excellent, but to make use of them in existing applications which don't support "TABLESPACE" keyword for CREATE TABLE commands, or for restoring backups from dumps and probably other cases it could be easier to use.

How to repeat:
mysql> CREATE DATABASE `foo`;
mysql> CREATE TABLESPACE foo_ts ADD DATAFILE '/var/lib/mysql_datafiles/foo.ibd' Engine=InnoDB;
Query OK, 0 rows affected (0.16 sec)
mysql> use foo;
Database changed
mysql> create table t(i int) ENGINE=InnoDB;

The table is not created in the `foo_ts` tablespace unless explicitly set in the CREATE TABLE command.

Suggested fix:
I suggest there should be a session variable which can be used to specify the default TABLESPACE value when it is not defined explicitly.

Example syntax:

```
mysql> USE TABLESPACE `my_tablespace`;
```

Or:

```
mysql> SET default_tablespace = 'my_tablespace';
```

This way one statement could be executed at the beginning of the connection which would affect all subsequent CREATE TABLE commands so that if `... TABLESPACE ...` is not defined the set one is used instead of the default one.

It could also be a global variable so that it could be set by a super user for rotating tablespaces.

Additionally, it would also be great to bind a user to a tablespace either exclusively, or just by default.

Example:

```
mysql> CREATE USER 'foo'@'%' TABLESPACE `foo_tablespace`;
```

So that the user's tables are always created in `foo_tablespace` by default.

Thanks!
[21 Oct 2020 14:15] MySQL Verification Team
Hi Mr. Mollenhour,

Thank you for your feature request.

We think that it does make sense, although, not with that syntax.

Verified as a feature request.