Synchronize SQL server data to mysql in real time

Source: Internet
Author: User
Tags mysql create mysql create database
1. install and install mysqlconnector2. configure mysqlconnectorODBC Data Manager-system DSN-add-mysqlODBC5.3ANSIdriver-enter CENAME such as jt, mysql ip address, user name, and password. create a connection server execsp_add1_server @ serverjt, -- datasourcename @ srvprodu in ODBC

1. install and install mysqlconnector2. configure mysqlconnectorODBC data Manager-system DSN-add-mysql ODBC 5.3 ANSI driver-enter the data source name, such as jt, mysql ip address, user name, and password. create a connection server exec sp_addmediaserver @ server = 'jt ', -- data source name @ srvprodu in ODBC

1. install and install mysqlconnector2. configure mysqlconnectorODBC data Manager-> system DSN-> Add-> mysql ODBC 5.3 ANSI driver-> Fill in data source name such as jt, mysql ip address, user name, and password. create a connection server exec sp_addmediaserver @ server = 'jt ', -- data source name @ srvproduct = 'mysql' in ODBC, -- casually @ provider = 'msdasql ', -- fix this @ datasrc = NULL, @ location = NULL, @ provstr = 'driver = {MySQL ODBC 5.3 ansi driver}; SERVER = 192.168.5.188; DATABASE = suzhou; UID = root; PORT = 3306; ', @ catalog = NULLexec sp_add1_srvlogin @ rmtsrvname = 'jt', @ useself = 'false', @ rmtuser = 'root', @ rmtpassword = 'Password '; select * from openquery (jt, 'select * FROM sz; ') GOUSE [master] GOEXEC master. dbo. sp_serveroption @ server = n'jt ', @ optname = n'rpc out', @ optvalue = n'true' GOEXEC master. dbo. sp_serveroption @ server = n'jt ', @ optname = n'remote proc transaction promotion', @ optvalue = n'false' GO --- 4. sqlserver and mysql create database AND table create database suzhou; create table sz (id int not null identity () primary key, orderno char (20) not null, ordertime datetime not null default getdate (), remark varchar (200) gocreate table sz (id int (11) not null, orderno char (20) not null, ordertime datetime (6) not null, remark varchar (200), primary key (id) engine = innodb default charset = utf8; --- 5. create LOOPBACK -- create loopback server link EXEC sp_addmediaserver @ server = n'loopback', @ srvproduct = n'', @ provider = n'sqlncli ', @ datasrc = @ SERVERNAMEgo -- sets the Server link option to prevent SQL Server from upgrading local transactions to distributed transactions due to Remote Procedure Calls (important) USE [master] GOEXEC master. dbo. sp_serveroption @ server = n'loopback', @ optname = n'rpc out', @ optvalue = n'true' GOEXEC master. dbo. sp_serveroption @ server = n'loopback', @ optname = n'remote proc transaction prodemo', @ optvalue = n'false' GO ---- 6. writing triggers and stored procedures ---- 6.1 insert -- rewrite the trigger use suzhougoalter trigger tr_insert_sz on suzhou. dbo. szfor insertasdeclare @ id int, @ orderno char (20), @ ordertime datetime, @ remark varchar (200) select @ id = id, @ orderno = orderno, @ ordertime = ordertime, @ remark = remark from inserted; beginprint @ idprint @ ordernoprint @ ordertimeprint @ remarkexec loopback. suzhou. dbo. sp_insert @ id, @ orderno, @ ordertime, @ remarkendgo -- stored PROCEDURE use suzhougocreate PROCEDURE sp_insert (@ id int, @ orderno char (20), @ ordertime datetime, @ remark varchar (200) asbeginset nocount on; Insert openquery (jt, 'select * from sz ') (id, orderno, ordertime, remark) values (@ id, @ orderno, @ ordertime, @ remark) ENDgo ---- 6.2 update -- rewrite the trigger use suzhougocreate trigger tr_update_sz on suzhou. dbo. szfor updateasdeclare @ orderno char (20), @ remark varchar (200) select @ orderno = orderno, @ remark = remark from inserted; beginexec loopback. suzhou. dbo. sp_update @ orderno, @ remarkendgo -- stored PROCEDURE use suzhougocreate PROCEDURE sp_update (@ orderno char (20), @ remark varchar (200) asbeginset nocount on; update openquery (jt, 'select * from sz ') set remark = @ remark where orderno = @ ordernoENDgo --- update data test use suzhougoupdate sz set remark = 'ocpyang' where orderno = 'a001' go ---- 6.3 delete -- rewrite trigger use suzhougocreate trigger tr_delete_sz on suzhou. dbo. szfor deleteasdeclare @ orderno char (20) select @ orderno = orderno from deleted; beginexec loopback. suzhou. dbo. sp_delete @ ordernoendgo -- stored PROCEDURE use suzhougocreate PROCEDURE sp_delete (@ orderno char (20) asbeginset nocount on; delete openquery (jt, 'select * from sz ') where orderno = @ ordernoENDgo --- delete data test use suzhougodelete from sz where orderno = 'a001' go

,

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.