|
|||
|
![]() One very interesting thing I noticed with MySQL was that if you delete a database, ibdata file doesn’t shrink by that much space to minimize disk usage. I deleted the database and checked usage of /usr/local/mysql/var folder and noticed that ibdata file is still the same size. So the problem I face now is, how do I claim back this space? After searching for a bit on google about this problem, apparently only way you can do that is by exporting your mysql databases, delete ibdata1 file, import databases. This creates new ibdata file with correct space usage. Atleast there is a way to get around this issue. But honestly, too much pain on production boxes where we might be trying to remove old databases to reclaim some of the hard drive space. An preventive measure one can use is to use option: That said, here are the steps:
#lets make a backup of current database. -p is used if there is pw set mysqldump -R -q -p -v --all-databases > /tmp/all.sql #stop mysql so we can move all the files from the dir /etc/init.d/mysql stop #move all the files mv -r /var/lib/mysql/* #install default dbs mysql_install_db #change ownership so mysql user can read/write to/from files chown -R mysql.mysql /var/lib/mysql/ #start mysql so we can import our dump /etc/init.d/mysql start #note there is no -p since defaults don't have mysql pw set mysql < /tmp/all.sql /etc/init.d/mysql restart
REMEMBER: Backup your data and be smart about using code found on internet. If you don’t know what you are doing, hire a consultant who does. Worked pretty awesomely! After restoring the data, I had some issues with authenticating to the server, so I logged in to MySQL and flushed the privileges, then restarted MySQL: $ mysql -u root -p Enter password: mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye $ /etc/init.d/mysql restart |