php - 如何仅使用 tcp/ip 将 sql-Dump 上传到远程数据库服务器
问题描述
我想用 php(curl?)从 mariadb 上传一个 sql-dump 到远程服务器。
我尝试了以下方法:
<?php
$file_name_with_full_path = '/path/file.sql';
if (function_exists('curl_file_create')) { // php 5.5+
$cFile = curl_file_create($file_name_with_full_path);
} else { //
$cFile = '@' . realpath($file_name_with_full_path);
}
$target_url = "server";
$post = array('extra_info' => '123456','file_contents'=> $cFile);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);
作为答案,我得到如下信息:
versionInfo-MariaDBrddas2_fafdas_Mmysql_native_password!��#08S01得到的数据包乱序
有人知道热修复吗?我想我可能很接近...
解决方案
根据错误消息,您似乎通过 curl 直接连接到 MariaDB 服务器。
Curl 不支持 MariaDB/MySQL 协议,MariaDB 服务器不提供获取(远程)sql-dumps 的接口。
你要做的是:
- 将转储文件上传到远程服务器(例如通过 ftp)
- 使用 mysql 命令行客户端在服务器上导入转储文件
如果您想自动执行此操作,则需要在服务器上执行脚本或 cron 作业,该作业经常检查包含上传转储文件的目录。
推荐阅读
- firebase - 我应该如何将 firestore 对象转换为可以在 expo/react-native 中使用的东西?
- node.js - mongoose.watch() 字段的名称自行更改
- sql-server - SCOPE_IDENTITY 返回 null,直到在 MS Access 中引发错误
- javascript - 当布尔值从假变为真时,如何在反应 16 中显示不同的 div?
- go - Golang 从 yaml 文件中提取值
- javascript - 尝试使用 Jest 对来自联合模块(webpack 5)的导入进行单元测试时出现“找不到模块”
- java - 嵌套for循环倒半金字塔
- azure - AKS 中的 Ocelot API 网关实现
- .htaccess - htaccess - 从文件中获取 IP 地址
- java - Spring Webflux - 反应式 Cassandra - 配置 ConsistencyLevel