Create a dblink to connect to mysql in sqlserver

At work, sqlserver needs to build mysql dblink, so that sqlserver program can directly access mysql database. The operation steps are recorded as follows:
1. Install mysql odbc driver on sqlserver database server.
2. Create the odbc data source (system DSN), select the odbc Driver of mysql, set the connection information (I wrote the username and password here), and define the data source name mysql1.
3. Open the sqlserver and go to the server object --> link Right-click on the server node to create a new linked server. Select the driver (microsoft ole db provider for odbc drivers), fill in the data source: mysql1, define the link name dblink1. The rest can be left blank~, in security, select "Use the current context of the login name to establish a connection", the above login mapping , and fill in the mapping relationship between the sqlserver user and the mysql database user.
4. You can use select * from openquery ([DBLINK1], 'select * from mysql_table') to query data. Note that the second parameter is the sql syntax of mysql and cannot contain []. Pay attention to the data type. An error will occur if the two databases are incompatible.


Date type, the field from mysql becomes varchar, you have to use convert(datetime, addDate) to convert it to sqlserver

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326221036&siteId=291194637