How MySQL connects to remote SQL

Source: Internet
Author: User

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)

 
 
  1. /* ① Code */
  2. /* MySQL trigger Writing Method */
  3. Delimiter //
  4. Create trigger insert_mysql_test before insert on Mysql_test
  5. For each row
  6. Begin
  7. Insert into Mysql_tem set tem_id = new test_id, tem_name = new test_name;
  8. /* Id after new. name is the field name of the Mysql_test table */
  9. End
  10. //
  11. /* MySQL trigger Writing Method */

Code

 
 
  1. /* ② Code */
  2. /* Stored Procedure */
  3. Use kk
  4. Go
  5. Create procedure select_x
  6. As
  7. Insert into SQL _tem (x_id, x_name) select * from openquery (GLB, 'select x_id, x_name from Mysql_tem ')
  8. Delete from SQL _tem
  9. Delete openquery (GLB, 'select * FROM Mysql_tem ')
  10. Go
  11. /* Stored Procedure */
 
 
  1. /* ③ Code */
  2. /* Create a trigger on the SQL _tem table */
  3. Create trigger tr_insert_tem on SQL _tem
  4. For insert
  5. As
  6. Insert into SQL _test
  7. Select * from inserted
  8. Go
  9. /* 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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.