English 中文(简体)
使用 SSH 隧道将本地 SQL 文件导入到远程服务器上的 MySQL
原标题:Import a local SQL File To MySQL on a Remote Server Using SSH Tunnel

我的本地主机 和一个遥控服务器之间 有连接 使用简便的SSH隧道

⊿闽玒

现在我需要一个命令 才能从我的本地机器( c: folder est. sql) 上获取 sql 文件, 然后在远程服务器上导入到 Mysql

我想也许...

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

然后执行类似命令

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

此命令没有起作用 。

我怎么能喜欢这个呢?

问题回答

您应该运行此命令

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

文件. sql 包含要运行和输出的 sql 查询。 log 只有当您有一个返回某东西的查询( 如选择) 时才有意义 。

在您的代码中,唯一不同的是 -p 选项和密码之间的空白空间。如果您使用 -p 选项,您必须在不留下空白空间的情况下写入密码。或者您可以使用选项 -- password=Password

我希望你能解决问题

您需要将 Mysql 命令附加到远程机中:

ssh remote_user@remote_server mysql -p testpass -u username testdb < c:folder	est.sql 
 1. mysql -h xxx -uxxx -pxxx . //login to the remote mysql
 2. use DATABASE.             //assign which db to import
 3. source path/to/file.sql  //the path can be your local sql file path.

参考文献:Inport SQL 文档进入 Mysql

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

语法:

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

在您传输文件使用后 :

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

mysql {mydbname} -- host {server}.mysql.database.azure.com -user {login}-password_password}<./{localdbbbbackupfile}.sql

作为管理下的服务, DevOps 和 CI/CD 工作流程在此点上变得更加受欢迎, 这些管理服务的多数提供者都希望消除在获取连接字符串正确性方面的人为错误部分。 如果您恰好使用 Azure、 AWS、 GCP 等, 通常会有一个页面或终端命令来显示这些字符串, 来帮助您方便地整合。 如果您重新使用类似的东西, 不要忘记检查它们的文档。 它们是自动生成的, 因此它们很可能是您可能使用的 db 版本的即时正确语法的最佳实践 。

以上命令来自Azure管理 Mysql DB 服务器实例的产品细节页面上的“连接字符串”。

许多这类服务自动生成模板, 供许多常见连接情景使用:

{
  "connectionStrings": {
    "ado.net": "Server={server}.mysql.database.azure.com; Port=3306; Database=mytestdb; Uid={login}; Pwd={password};",
    "jdbc": "jdbc:mysql://{server}.mysql.database.azure.com:3306/mytestdb?user={login}&password={password}",
    "jdbc Spring": "spring.datasource.url=jdbc:mysql://{server}.mysql.database.azure.com:3306/mytestdb  spring.datasource.username={login}  spring.datasource.password={password}",
    "mysql_cmd": "mysql mytestdb --host {server}.mysql.database.azure.com --user {login} --password={password}",
    "node.js": "var conn = mysql.createConnection({host:  {server}.mysql.database.azure.com , user:  {login} , password: {password}, database: mytestdb, port: 3306});",
    "php": "$con=mysqli_init(); [mysqli_ssl_set($con, NULL, NULL, {ca-cert filename}, NULL, NULL);] mysqli_real_connect($con,  {server}.mysql.database.azure.com ,  {login} ,  {password} ,  mytestdb , 3306);",
    "python": "cnx = mysql.connector.connect(user= {login} , password= {password} , host= {server}.mysql.database.azure.com , port=3306, database= mytestdb )",
    "ruby": "client = Mysql2::Client.new(username:  {login} , password:  {password} , database:  mytestdb , host:  {server}.mysql.database.azure.com , port: 3306)"
  }
}

您可以使用 pscp 将文件上传到服务器。 转到您的命令行并输入此

pscp.exe c:folder	est.sql [email protected]:/serverpath




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签