我有一个带有 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 中的过程。
我要做的是:
- 修改过程,以便将输出存储在表中。
- 使用
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/