Beberapa waktu lalu, Saya melakukan migrasi server ke komputer baru dan tentunya database juga harus dipindahkan. Jika file database yang akan dimigrasi tidaklah besar, itu tidak jadi masalah. Tetapi file mysql yang akan Saya transfer ini mempunyai ukuran yang lumayan besar. Yang satu berukuran 50MB dan satunya berukuran hampir 650MB.
Untuk file mysql dump yang berukuran diantara 50-100MB, Saya menggunakan tools BigDump, dan itu masih berhasil dilakukan. Permasalahannya ketika file mysql yang harus diimport berukuran diatas 500MB. BigDump sendiri sepertinya selalu mengalami time out. Setting $linespersession juga sudah dilakukan sesuai petunjuk dari website BigDump untuk mengatasi time out, tetapi tetap tidak berhasil.
MySQL Command Line
Sebagai informasi, langkah berikut juga sudah dicoba di file mysql dump dengan ukuran 6GB.
Sebelum melakukan proses ini, pastikan file mysql.sql Anda sudah berada di satu lokasi dengan proses berikut.
Dari Linux command line, ketikkan :
agung@library:~$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8118 Server version: 5.5.47-0ubuntu0.14.04.1 (Ubuntu) Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Sekarang Anda berada di mysql shell. Dari sini, tentukan database yang akan dipilih.
mysql> use ocs; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed
Berikutnya, ikuti perintah berikut :
mysql> set global net_buffer_length=1000000; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> set global max_allowed_packet=1000000000; Query OK, 0 rows affected, 1 warning (0.00 sec)
Menonaktifkan pengecekan forein key untuk menghindari delays, kesalahan dan aktivitas yang tidak diinginkan.
mysql> SET foreign_key_checks = 0; Query OK, 0 rows affected (0.00 sec) mysql> SET UNIQUE_CHECKS = 0; Query OK, 0 rows affected (0.00 sec) mysql> SET AUTOCOMMIT = 0; Query OK, 0 rows affected (0.00 sec)
Lalu pilih file *.sql yang akan diimport
mysql> source ocs.sql Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.03 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 16 rows affected (0.00 sec) Records: 16 Duplicates: 0 Warnings: 0 ... Query OK, 1564 rows affected (0.03 sec) Records: 1564 Duplicates: 0 Warnings: 0
Kalau sudah, kembalikan lagi setingan ke awal
mysql> SET foreign_key_checks = 1; Query OK, 0 rows affected (0.00 sec) mysql> SET UNIQUE_CHECKS = 1; Query OK, 0 rows affected (0.00 sec) mysql> SET AUTOCOMMIT = 1; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye
Bash Script
Kita bisa membuat skrip yang jelasnya memudahkan kita dalam melakukan proses import file.sql.
#!/bin/sh # store start date to a variable imeron=`date` echo "Import dimulai: OK" dumpfile="/home/agungprasetyo/ocs.sql" ddl="set names utf8; " ddl="$ddl set global net_buffer_length=1000000;" ddl="$ddl set global max_allowed_packet=1000000000; " ddl="$ddl SET foreign_key_checks = 0; " ddl="$ddl SET UNIQUE_CHECKS = 0; " ddl="$ddl SET AUTOCOMMIT = 0; " # jika file dump Anda tidak membuat database, gunakan use ddl="$ddl USE ocs; " ddl="$ddl source $dumpfile; " ddl="$ddl SET foreign_key_checks = 1; " ddl="$ddl SET UNIQUE_CHECKS = 1; " ddl="$ddl SET AUTOCOMMIT = 1; " ddl="$ddl COMMIT ; " echo "Import dimulai: OK" time mysql -h 127.0.0.1 -u root -proot -e "$ddl" # store end date to a variable imeron2=`date` echo "Proses import dimulai:$imeron" echo "Proses import selesai:$imeron2" echo "Sumber: https://cmanios.wordpress.com/2013/03/19/import-a-large-sql-dump-file-to-a-mysql-database-from-command-line/"
Semoga penjelasan diatas bisa memberikan manfaat.
putu
thanks gan, ini yang saya cari setelah muter muter. data 890MB udah bikin ppuyeng
Hardy HP
Terima kasih Gan. Panduannya mantap : jelas, to the point and terbuki ampuh menagani file-file mysql ukuran jumbo.
Hardy HP
Sekalian mohon info kalau misalnya seting yang diubah tadi nggak kita kembalikan ke nilai awal pengaruhnya kira-kira apa ya Gan. Terima kasih.