简体   繁体   English

如何定义 mysql 数据库的最大大小

[英]How to define maximum size for mysql database

Is there any way how to define maximum size for mysql database?有什么方法可以定义 mysql 数据库的最大大小?

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.最接近设置硬大小限制的是定义 InnoDB 系统表空间的大小时。 See documentation: https://dev.mysql.com/doc/refman/8.0/en/innodb-init-startup-configuration.html#innodb-startup-data-file-configuration请参阅文档: 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.请注意,如果您设置了此大小限制,您将无法使用 file-per-table 表空间或通用表空间。 You'd set innodb_file_per_table=OFF and all tables would share the system tablespace.您将设置innodb_file_per_table=OFF ,所有表将共享系统表空间。

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.如果您需要执行任何 ALTER TABLE 或 OPTIMIZE TABLE 操作并且系统表空间中没有足够的可用空间,这将变得非常不舒服。 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 .您可能会遇到这样一种情况,如果不删除或截断某些表,或者临时使用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. MySQL 中没有在 file-per-table 表空间或通用表空间上设置最大大小的功能。

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.同样在 MySQL 的现代版本中,仍然在系统表空间之外创建了其他文件,例如临时表、回滚段和双写缓冲区。 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.然后是查询日志和二进制日志,它们可能会占用大量空间,具体取决于您的流量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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