首页 > 解决方案 > 如何仅使用 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得到的数据包乱序

有人知道热修复吗?我想我可能很接近...

标签: phpwindowscurlmariadb

解决方案


根据错误消息,您似乎通过 curl 直接连接到 MariaDB 服务器。

Curl 不支持 MariaDB/MySQL 协议,MariaDB 服务器不提供获取(远程)sql-dumps 的接口。

你要做的是:

  1. 将转储文件上传到远程服务器(例如通过 ftp)
  2. 使用 mysql 命令行客户端在服务器上导入转储文件

如果您想自动执行此操作,则需要在服务器上执行脚本或 cron 作业,该作业经常检查包含上传转储文件的目录。


推荐阅读