使用SSH隧道将本地SQL文件导入远程服务器上的MySQL

时间:2022-05-13 05:28:24

I have a connection between my localhost and a remote server using putty SSH tunnel.

我使用putty SSH隧道在localhost和远程服务器之间建立连接。

Thats fine.

没关系。

Now I need a command to get the sql file on my local machine i.e. c:\folder\test.sql and import it into mysql on the remote server

现在我需要一个命令来获取我的本地机器上的sql文件,即c:\ folder \ test.sql并将其导入远程服务器上的mysql

I thought maybe...

我想也许......

mysql -u prefix_username -p testpass -h localhost -P 3307 prefix_testdb

then do a command like

然后做一个像这样的命令

mysql -p testpass -u prefix_username prefix_testdb < c:\folder\test.sql 

this command did not work.

这个命令不起作用。

How can I acheive this?

我该如何实现这一目标?

5 个解决方案

#1


28  

You should run this command

您应该运行此命令

mysql -h host -u user_name -pPassword database < file.sql > output.log

file.sql contains the sql queries to run and output.log makes sense only when you have a query that returns something (like a select)

file.sql包含要运行的sql查询和output.log只有当你有一个返回某些东西的查询时才有意义(比如select)

The only thing different I can see in your code is the blank space between the -p option and the password. If you use the -p option, you must write the password without leaving any blank space. Or you just can user the option --password=Password

我在代码中看到的唯一不同的是-p选项和密码之间的空白。如果使用-p选项,则必须在不留空格的情况下编写密码。或者您只需使用选项--password =密码即可

I hope you can solve the problem

我希望你能解决问题

#2


9  

You will need to ssh to the remote machine with the mysql command appended:

您将需要使用附加的mysql命令ssh到远程计算机:

ssh remote_user@remote_server mysql -p testpass -u username testdb < c:\folder\test.sql 

#3


6  

 1. mysql -h xxx -uxxx -pxxx . //login to the remote mysql
 2. use DATABASE.             //asign which db to import
 3. source path/to/file.sql  //the path can be your local sql file path.

Refference: Import SQL file into mysql

参考:将SQL文件导入mysql

#4


3  

Use 'scp' to copy and mysql to insert to you local machine.

使用'scp'复制和mysql插入本地机器。

Syntax:

句法:

scp remote_user@remove_server:/path/to/sql/file.sql ~/path/to/local/directory

after you transfered the file use:

转移文件后使用:

mysql -uYouUserName -p name_of_database_to_import_to < ~/path/to/local/directory/file.sql

#5


-1  

You can use pscp to upload file to the server. Go to your command line and type this

您可以使用pscp将文件上载到服务器。转到命令行并键入此内容

pscp.exe c:\folder\test.sql usernameoftheserver@websitename.com:/serverpath

#1


28  

You should run this command

您应该运行此命令

mysql -h host -u user_name -pPassword database < file.sql > output.log

file.sql contains the sql queries to run and output.log makes sense only when you have a query that returns something (like a select)

file.sql包含要运行的sql查询和output.log只有当你有一个返回某些东西的查询时才有意义(比如select)

The only thing different I can see in your code is the blank space between the -p option and the password. If you use the -p option, you must write the password without leaving any blank space. Or you just can user the option --password=Password

我在代码中看到的唯一不同的是-p选项和密码之间的空白。如果使用-p选项,则必须在不留空格的情况下编写密码。或者您只需使用选项--password =密码即可

I hope you can solve the problem

我希望你能解决问题

#2


9  

You will need to ssh to the remote machine with the mysql command appended:

您将需要使用附加的mysql命令ssh到远程计算机:

ssh remote_user@remote_server mysql -p testpass -u username testdb < c:\folder\test.sql 

#3


6  

 1. mysql -h xxx -uxxx -pxxx . //login to the remote mysql
 2. use DATABASE.             //asign which db to import
 3. source path/to/file.sql  //the path can be your local sql file path.

Refference: Import SQL file into mysql

参考:将SQL文件导入mysql

#4


3  

Use 'scp' to copy and mysql to insert to you local machine.

使用'scp'复制和mysql插入本地机器。

Syntax:

句法:

scp remote_user@remove_server:/path/to/sql/file.sql ~/path/to/local/directory

after you transfered the file use:

转移文件后使用:

mysql -uYouUserName -p name_of_database_to_import_to < ~/path/to/local/directory/file.sql

#5


-1  

You can use pscp to upload file to the server. Go to your command line and type this

您可以使用pscp将文件上载到服务器。转到命令行并键入此内容

pscp.exe c:\folder\test.sql usernameoftheserver@websitename.com:/serverpath