LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Read MySQL database size with BASH script (http://www.linuxquestions.org/questions/linux-server-73/read-mysql-database-size-with-bash-script-730640/)

Datakraft 06-04-2009 07:53 AM

Read MySQL database size with BASH script
 
Hello.

This is my first thread here at LinuxQuestions, so be nice to me. I think i have found the right section, if not a nice moderator can help me find to the right section.

I creating a BASH-script for the moment and i need the know the size of a (not the whole one, just one) MySQL database. Is this possible to output data from MySQL and put it into variable in my script?

Thanks for taking your time.

soleilarw 06-04-2009 09:25 AM

You need to find the location where mysql databases are stored. On my Fedora that's in /var/lib/mysql. Each database has it's own directory. Use 'du' to calculate the directory size. Another approach is to dump a database by using mysqldump, and getting the size of that file.

Linux Archive

Datakraft 06-05-2009 02:03 AM

Quote:

Originally Posted by soleilarw (Post 3562977)
Another approach is to dump a database by using mysqldump, and getting the size of that file.

I suppose you must have root rights to do that?

Quote:

Originally Posted by soleilarw (Post 3562977)
Each database has it's own directory.

Is i possible to change so each users databases is stored in their home directory in MySQL? And if so please provide a howto.

Code:

/data/user/www
          database


soleilarw 06-05-2009 05:13 AM

Dumping a database only requires to know the sql username and sql password to access that specific database. Sql authentication is different from the system's user authentication. You don't need to be "UNIX root", but the "mySQL root" account or a privileged mySQL user account is needed.

AFAIK mySQL doesn't support having databases in different locations, but it should be possible to move the database directory to some other location and leaving a softlink behind which points to the new location. For this you certainly will need UNIX root privileges. Theoretically it should work.

Datakraft 06-05-2009 05:16 AM

Quote:

Originally Posted by soleilarw (Post 3563987)
AFAIK mySQL doesn't support having databases in different locations, but it should be possible to move the database directory to some other location and leaving a softlink behind which points to the new location. For this you certainly will need UNIX root privileges. Theoretically it should work.

But i found something in the MySQL configuration called datadir?


All times are GMT -5. The time now is 08:30 PM.