简体   繁体   中英

How to define maximum size for mysql database

Is there any way how to define maximum size for mysql database?

For example:

CREATE DATABASE `foo` WITH maxSize=1gb;

The closest thing to setting a hard size limit is when defining the size of the InnoDB system tablespace. See documentation: https://dev.mysql.com/doc/refman/8.0/en/innodb-init-startup-configuration.html#innodb-startup-data-file-configuration

Example:

[mysqld]
innodb_data_file_path=ibdata1:12M:autoextend:max:500M

Note that you would not be able to use file-per-table tablespaces or general tablespaces if you did set this size limit. You'd set innodb_file_per_table=OFF and all tables would share the system tablespace.

This will get very uncomfortable if you need to do any ALTER TABLE or OPTIMIZE TABLE operations and there isn't enough free space in the system tablespace. You may get into a situation where you can't do those operations without dropping or truncating some tables, or else temporarily using innodb_file_per_table=ON .

There is no feature in MySQL to set a maximum size on a file-per-table tablespace or a general tablespace.

Also in modern versions of MySQL, there are still other files created outside the system tablespace, like for temporary tables and the rollback segment and the doublewrite buffer. I don't think the size of these can be controlled in the same way.

Then there are query logs and binary logs, which can take a lot of space depending on your rate of traffic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM