使用putty导入sql.gz文件并将其插入数据库
我想用SSH将 sql.gz
文件插入我的数据库。我该怎么办?
I want to insert a sql.gz
file into my database with SSH. What should I do?
例如我有一个电话号码的数据库,名称是 numbers.sql.gz
,这是什么类型的文件,如何将此文件导入我的数据库?
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?
该文件是一个gzip压缩文件)SQL文件,几乎可以肯定是以.sql作为扩展名的纯文本文件。您需要做的第一件事是通过scp将文件复制到数据库服务器。我认为PuTTY是pscp.exe
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
# Copy it to the server via pscp
C:\> pscp.exe numbers.sql.gz user@serverhostname:/home/user
然后SSH进入你的服务器并使用 gunzip解压缩文件
Then SSH into your server and uncompress the file with gunzip
user@serverhostname$ gunzip numbers.sql.gz
user@serverhostname$ ls
numbers.sql
最后,使用<
输入重定向运算符将其导入MySQL数据库:
Finally, import it into your MySQL database using the <
input redirection operator:
user@serverhostname$ mysql -u mysqluser -p < numbers.sql
如果numbers.sql文件没有创建数据库但希望有一个数据库存在已经,您还需要在命令中包含数据库:
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:
user@serverhostname$ mysql -u mysqluser -p databasename < numbers.sql
如果你能够从外面直接连接MySQL服务器,那么你可以使用本地MySQL客户端而不必复制和SSH。在这种情况下,您只需要一个可以在Windows上解压缩.gz文件的实用程序。我相信7zip会这样做,或者你可以获得Windows的 gzip / gunzip二进制文件。
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.