mysql - 如何调用远程 MySQL Ubuntu 服务器上的存储过程?

标签 mysql ubuntu stored-procedures remote-access

我有一个带有 MySQL 和许多存储过程的 Ubuntu 服务器(服务器 A)和另一个带有 MySQL 的 Ubuntu 服务器(服务器 B)。

我想用服务器 A 上存储过程的数据填充服务器 B 上的数据库。

此时我想测试连接,但没有成功。

我在服务器 B 上尝试过:

mysql> EXEC server_A_IP.DB_name.username.sp_courses();

但它给出了这个错误:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'EXEC server_ip.db_name.owner.sp_courses()' at line 1

这是我最终想要做的一个例子:

在服务器 B 上我有这个表:

mysql> describe Course;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| CID   | int(11)     | NO   | PRI | 0       |       |
| name  | varchar(50) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

服务器 A 上的存储过程返回如下数据:

call sp_courses();-- where the parameter indicates level 1.Returns [courseID, name]

1   CS1
2   CS2
10  CS3
12  CS4
13  CS5S

我可以通过不同服务器上的存储过程将数据填充到表中吗?

最佳答案

据我所知,您无法从服务器 B 调用存储在服务器 A 中的过程。

我要做的是:

  1. 修改过程,以便将输出存储在表中。
  2. 使用mysqldump转储此输出表的数据并将其存储在其他服务器中。

示例:

在服务器 A 上,过程可能如下所示:

delimiter $$
create procedure my_procedure()
begin
    -- Create a table to store the output:
    drop table if exists temp_result;
    create table temp_result (
        CID int not null primary key,
        name varchar(50)
    );
    -- Populate the table
    insert into temp_result
        select ...
end $$
delimiter ;

在服务器 B 上,在 shell 中执行以下语句,而不是在 MySQL CLI 中:

mysqldump <options_A> db_A temp_result --no-create-db --add-drop-table | mysql <options_B> db_B

地点:

  • <options_A>从服务器 B 连接到服务器 A 所需的选项:
    -h <IP of server A> -u <user> -p<password> .
  • db_A服务器A中存储结果的数据库
  • <options_B>连接到服务器 B 所需的选项:
    -h localhost -u <user> -p<password>

关于mysql - 如何调用远程 MySQL Ubuntu 服务器上的存储过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38798210/

相关文章:

带有自定义参数的 Mysql SP

mysql - SQL 查询 : Selecting an entry from one table and adding values from another

mysql - phpmyadmin中的奇怪错误,已成功安装但仍然无法运行

mysql - INSERT INTO 不重复的特定列

mysql - 在每个循环中将 xml 写入 mysql

ubuntu - cmake 为 root 工作而不为其他用户工作

ubuntu - 无法通过 apache 访问已安装的 s3 存储桶文件

ubuntu - visual studio code 1 无法使用 xrdp 在 ubuntu 上启动

mysql - 存储过程mysql workbench中缺少分号错误

stored-procedures - 给定出现在 proc 中的文本字符串,在 db 中查找 Sybase 存储过程