LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-04-2009, 07:53 AM   #1
Datakraft
LQ Newbie
 
Registered: May 2009
Posts: 10

Rep: Reputation: 0
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.
 
Old 06-04-2009, 09:25 AM   #2
soleilarw
Member
 
Registered: Apr 2009
Posts: 107

Rep: Reputation: 19
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

Last edited by soleilarw; 06-18-2009 at 04:32 AM.
 
Old 06-05-2009, 02:03 AM   #3
Datakraft
LQ Newbie
 
Registered: May 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by soleilarw View Post
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 View Post
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
 
Old 06-05-2009, 05:13 AM   #4
soleilarw
Member
 
Registered: Apr 2009
Posts: 107

Rep: Reputation: 19
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.
 
Old 06-05-2009, 05:16 AM   #5
Datakraft
LQ Newbie
 
Registered: May 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by soleilarw View Post
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?
 
  


Reply

Tags
bash, database, mysql, read, size



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Read Only MySQL Database richinsc Linux - Server 2 09-25-2008 08:54 PM
Bash script for database backup #cousin# Programming 8 08-29-2008 06:00 AM
limit Mysql database size per user account cksoo Linux - Server 3 07-10-2007 02:58 PM
Cannot running export database using bash script tovohery Linux - General 2 03-22-2007 06:59 AM
sed script to read only columns 4 to 6 in output database cranium2004 Programming 10 02-28-2006 07:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration