I want to insert a sql.gz
file into my database with SSH. What should I do?
For example I have a database from telephone numbers that name is numbers.sql.gz
, what is this type of file and how can I import this file into my database?
I want to insert a sql.gz
file into my database with SSH. What should I do?
For example I have a database from telephone numbers that name is numbers.sql.gz
, what is this type of file and how can I import this file into my database?
Login into your server using a shell program like putty.
Type in the following command on the command line
where
DB_File_Name.sql.gz
= full path of the sql.gz file to be importedusername
= your mysql usernameTarget_DB_Name
= database name where you want to import the databaseWhen you hit enter in the command line, it will prompt for password. Enter your MySQL password.
You are done!
If you have scp then:
To move your file from local to remote:
To move your file from remote to local:
To export your mysql file without login in to remote system:
To import your mysql file withoug login in to remote system:
Note: Make sure you have network access to the ipaddress of remote host
To check network access:
Creating a Dump File SQL.gz on the current server
Optional: Command Arguments for connection
Importing the dumpfile created above to a different Server
Optional: Command Arguments for connection
mysql: [Warning] Using a password on the command line interface can be insecure. 1.0GiB 00:06:51 [8.05MiB/s] [<=> ]
The optional software packages are helpful to import your database SQL file faster
for faster zipping of the output
If you've got many database it import and the dumps is big (I often work with multigigabyte Gzipped dumps).
There here a way to do it inside mysql.
The only advantage this has over
is that you can easily do multiple without enter the password lots of times.
Without a separate step to extract the archive:
I use the above snippet to re-import mysqldump-backups, and the following for backing it up.
The file is a gzipped (compressed) SQL file, almost certainly a plain text file with .sql as its extension. The first thing you need to do is copy the file to your database server via scp.. I think PuTTY's is pscp.exe
Then SSH into your server and uncompress the file with
gunzip
Finally, import it into your MySQL database using the
<
input redirection operator:If the numbers.sql file doesn't create a database but expects one to be present already, you will need to include the database in the command as well:
If you have the ability to connect directly to your MySQL server from outside, then you could use a local MySQL client instead of having to copy and SSH. In that case, you would just need a utility that can decompress .gz files on Windows. I believe 7zip does so, or you can obtain the gzip/gunzip binaries for Windows.