15

Is there a command to check how much room MySql has left?

2
  • I think you'd have better luck with this one on ServerFault Commented Jul 7, 2010 at 5:38
  • Thanks everyone for the answers I didn't know if mysql could limit the amount of data it could store. If i keep an eye on the disk space of the server I will be able to have sort of an idea of how much room is left for the database. Commented Jul 12, 2010 at 3:05

4 Answers 4

11
+25

@PeterTurner I have an earlier post from Oct 29, 2010 on how much space is used by MySQL

How to monitor MySQL space?

However, I know this is not what you are looking for. You do not want how much diskspace MySQL is using. Your question is simply how much space is left where mysql is writing. That's not a MySQL operation. Nevertheless, you can take advantage of MySQL to quickly answer your question in conjunction with the local OS. In conjunction with what? The command df

The df displays six columns

[root@******** ~]# df -h | head -1
Filesystem            Size  Used Avail Use% Mounted on

That breaks down to

  • Filesystem
  • Size
  • Used
  • Avail
  • Use%
  • Mounted on

You need to get column 4, Avail. There is one problem with this idea: If the filesystem name is too long, that moves columns 2-6 to the next line. Here is an example:

[root@******** ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg1-root 122236876   9196208 106731192   8% /
/dev/mapper/vg2-data01
                     1726991928 810877540 828388308  50% /data
/dev/sdc1            3844656172 559221048 3090137848  16% /backup
/dev/sda1               101086     17569     78298  19% /boot
tmpfs                 98976204         0  98976204   0% /dev/shm
none                  16777216     58576  16718640   1% /var/tmpfs
[root@i******** ~]# df -h /var/lib/mysql
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg2-data01
                      1.7T  774G  791G  50% /data

Note that the data folder's filesystem name moves columns 2-6 to the next line.

Therefore, just do a line count of the df display. If there are two lines, get token #4. If there are three lines, get token #3. Here is the shell script that will echo the available space where mysql's datadir is mounted:

MYSQL_USER=root
MYSQL_PASS=rootpassword
MYSQL_CONN="-u${MYSQL_USER} -p${MYSQL_PASS}"
SQLSTMT="SHOW VARIABLES LIKE 'datadir'"
DATADIR=`mysql ${MYSQL_CONN} -ANe"${SQLSTMT}" | awk '{print $2}'`
df -B 1 ${DATADIR} > /tmp/dfmysql.txt
LC=`wc -l < /tmp/dfmysql.txt`
if [ ${LC} -eq 2 ] ; then SPC=`tail -1 /tmp/dfmysql.txt | awk '{print $4}'` ; fi
if [ ${LC} -eq 3 ] ; then SPC=`tail -1 /tmp/dfmysql.txt | awk '{print $3}'` ; fi
echo ${SPC}

Notice the line that has

df -B 1 ${DATADIR} > /tmp/dfmysql.txt

This will give the df report in bytes. You can change it:

  • df gives output in KB
  • df -B 1K gives output in KB
  • df -B 1M gives output in MB

The only mysql interaction is retrieving datadir from mysql.

Give it a Try !!!

Sign up to request clarification or add additional context in comments.

Comments

6

Usually, MySQL is not limiting the space it can use. You can use all the space your hard disk(s) contain.

There are a few exceptions though, for really big tables. For example the MyISAM Storage Engine, there is a Max_Data_Length which determines how much data a table can handle (depending on number of bytes used for pointers)... but by default 4Gb per table is no problem, and from MySQL 5 a table can store 256TB.

Comments

5

MySQL using your disk space, so when your disk is having room left then MySQL also should also have room.

In MySQL, use the SHOW TABLE STATUS command, and look at the Data_length column for each table, which is in bytes.

See also :

  1. How to monitor MySQL space?
  2. How can you determine how much disk space a particular MySQL table is taking up?
  3. Mysql table size on the HDD
  4. How do I check how much disk space my database is using?

1 Comment

I'd like to know how much space is left on the hard drive. I want tell a user running a program to think twice before running a utility which will effectively quadruple the size of their database. The program is not on the database server but connected via ODBC. I can do this (more or less) in Microsoft SQL using XP_FIXEDDRIVES, but I need to support MSSQL and MYSQL so I'm looking for a comparable routine.
0

Confusing, It will depends on your hard disk space.

If you have space in you Hard Drive where you have been installed mysql server, You can store million ++ records.

1 Comment

Do you have any idea how to figure out how much free space is left on the disk purely through SQL Queries?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.