The question of 'how MySQL connects to a remote SQL 'has been considered for more than half a month, previously, I had been struggling to find a direct method similar to how I made 'SQL connection to remote mysql' and find a suitable interface.
However, after a long effort, I still failed. So I thought of another method to achieve the same result. When a record is inserted in MySQL, the remote SQL statement inserts the same record.
Since I have already made 'how to connect to remote mysql ',
Article address: http://database.51cto.com/art/201008/221118.htm)
I used two triggers, one stored procedure and one job, to achieve the same effect.
(I used a picture to illustrate my practices)
- /* ① Code */
- /* MySQL trigger Writing Method */
- Delimiter //
- Create trigger insert_mysql_test before insert on Mysql_test
- For each row
- Begin
- Insert into Mysql_tem set tem_id = new test_id, tem_name = new test_name;
- /* Id after new. name is the field name of the Mysql_test table */
- End
- //
- /* MySQL trigger Writing Method */
Code
- /* ② Code */
- /* Stored Procedure */
- Use kk
- Go
- Create procedure select_x
- As
- Insert into SQL _tem (x_id, x_name) select * from openquery (GLB, 'select x_id, x_name from Mysql_tem ')
- Delete from SQL _tem
- Delete openquery (GLB, 'select * FROM Mysql_tem ')
- Go
- /* Stored Procedure */
- /* ③ Code */
- /* Create a trigger on the SQL _tem table */
- Create trigger tr_insert_tem on SQL _tem
- For insert
- As
- Insert into SQL _test
- Select * from inserted
- Go
- /* Triggers created on the tem table */
<Supplement> I used SQL Server2005 visualization for that job. The most important operation is to regularly execute the 'exec select_x 'operation. Execution of stored procedures)
Add one for you to see. It can also be found in SQL 2000 Enterprise Manager.
Original article title: how MySQL connects to remote SQL
Link: http://www.cnblogs.com/guolebin7/archive/2010/09/01/1815304.html
Edit recommendations]