Jika Anda telah menyiapkan akses SSH untuk sebuah paket maka Anda dapat menjalankan instruksi baris perintah berikut untuk mengimpor database MySQL:
mysql -h nama host -u nama pengguna -p nama pengguna < databasefile.sql
Perintah di atas terhubung ke database Anda dengan -h (nama host) -u (nama pengguna) -p (nama database dalam hal ini) kemudian file yang tidak di-zip < databasefile.sql
Anda kemudian akan diminta untuk memasukkan kata sandi untuk database. Masukkan kata sandi dan tekan enter.
File terkompresi
Jika file database di-zip maka Anda harus meng-unzipnya terlebih dahulu, kemudian Anda dapat menggunakan salah satu perintah berikut:
Untuk file .zip Anda dapat menggunakan perintah unzip:
- unzip databasefile.sql.zip
- mysql -h hostname -u username -p username < databasefile.sql
Untuk file .gz Anda dapat menggunakan perintah gunzip:
- gunzip databasefile.sql.gz
- mysql -h hostname -u username -p username < databasefile.sql
How do I import a .sql file via the command-line?
If you've set up SSH access for a package then you can run the following command-line instructions to import a MySQL database:
mysql -h hostname -u username -p username < databasefile.sql
The above command connects to your database with the -h (hostname) -u (username) -p (database name in this case) then the unzipped file < databasefile.sql
You will then be prompted to enter a password for the database. Input the password and press enter.
Compressed files
If the database file is zipped then you will need to unzip it first, then you can use one of the following commands:
For a .zip file you can use the unzip command:
- unzip databasefile.sql.zip
- mysql -h hostname -u username -p username < databasefile.sql
For a .gz file you can use the gunzip command:
- gunzip databasefile.sql.gz
- mysql -h hostname -u username -p username < databasefile.sql
