How To Setup Disk Quotas For MySQL Database

263
0

MySQL server has no support for preventing disk from getting filled up. You need to depend upon external configurations. Let us see how to use standard Linux disk quota to limit user database size.

Suppose you have a user foo on the system as well as on MySQL. Now how do you limit space for foo?

Step #1: Create a separate directory for databases in foo’s home say /home/foo/dbs with ownership mysql:foo and permissions 3755:

mkdir /home/foo/dbs && chown mysql:foo /home/foo/dbs && chmod 3755 /home/foo/dbs

Step #2: Now move all foo’s databases from /var/lib/mysql to /home/foo/dbs

 mkdir /root/backup
 cp -avr /var/lib/mysql/* root/backup
 mv /var/lib/mysql/database-name /home/foo/dbs/
 chown -Rf mysql:foo /home/foo
 chmod -Rf 3755 /home/foo
 ln -s /var/lib/mysql/database-name /home/foo/dbs/database-name -v

Finally, restart mysqld. If mysqld starts with OK status, then its working else it isn’t:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.