gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 01:37:07 25 4
gpt4 key购买 nike

我有一个带有 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com