MySQLのダンプ/インポート、innodbのサイズダウン
innnodbがデカくなってしまったので、一度エクスポートしてからインポートし直して
データファイルのスリム化を図ってみた。
どうも、一度エクスポートしてからインポートしないと
InnnoDBのデータファイルは小さくならないらしい。
以下の手順で実行するとInnoDBのファイルが小さくできる。
MySQLサービスの停止
[root@host mysql]# service mysqld stop ※ログ取り忘れ
エクスポート(MySQLのDB全体のバックアップ)
[root@host ~]# mysqldump -A -a -e -F -q -u root -p --add-drop-table > mydb.dump Enter password:※デフォルトはパスワード無しなのでそのままEnter
データファイルの削除
[root@host lib]# cd mysql [root@host mysql]# ls ib_logfile0 ib_logfile1 ibdata1 mysql test wikipedia [root@host mysql]# ls -ltra 合計 25169960 drwxr-xr-x 20 root root 4096 2月 17 18:33 .. drwx------ 2 mysql mysql 4096 2月 17 19:40 test drwx------ 2 mysql mysql 4096 2月 17 19:40 mysql drwx------ 2 mysql mysql 4096 2月 18 17:39 wikipedia -rw-rw---- 1 mysql mysql 67108864 2月 22 11:38 ib_logfile1 drwxr-xr-x 5 mysql mysql 4096 2月 22 12:05 . -rw-rw---- 1 mysql mysql 25614614528 2月 22 12:05 ibdata1 -rw-rw---- 1 mysql mysql 67108864 2月 22 12:05 ib_logfile0 [root@host mysql]# rm -rf *
サービス起動
[root@host mysql]# service mysqld start ※ログファイルやデータファイルに指定したディレクトリにファイルがないと 勝手に初期化が行われる。 MySQL データベースを初期化中: Installing MySQL system tables... OK Filling help tables... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h host password 'new-password' Alternatively you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /usr ; /usr/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /usr/mysql-test ; perl mysql-test-run.pl Please report any problems with the /usr/bin/mysqlbug script! [ OK ] mysqld を起動中: [ OK ]
インポート
[root@host mysql_dump]# mysql -u root -p < mydb.dump Enter password:
一応これで終了。
ただ、ユーザー情報とかはエクスポートされていなかったらしく、
新しくユーザーは作り直さないといけない。