将MySQL库的表转入到MSSQL中的某个库中(Employees下的Employees表 → pubs库下)_2
将MySQL库的表转入到MSSQL中的某个库中(Employees下的Employees表 → pubs库下, 此pubs下的表名是employee,不冲突),
方法大致以下几个(另有其他方法待补充),其他 MSSQL to MySQL的以后也可体验下.
1)MySQL ODBC Connector(Link转换)
2)Navicat Premium
3)MSSQL Server版本相对应的SQL Server Migration Assistant for MySQL
--------------------------------------------------------------------------------------------------------------------------------------
本文按照下述步骤进行:
1. 安装驱动(如之前安装过MySQL 里面会配带安装了驱动)
2. 配置ODBC驱动
3. 建立MySQL与MSSQL的连接
4. 在2个数据表之间导入数据
select * into pubs.dbo.employees
from openquery(mysql,'select * from employees.employees')
--------------------------------------------------------------------------------------------------------------------------------------
Info 1)之前就已安装好MySQL 8.0.18,查看MySQL版本:
Info 2)查看MSSQL版本(为了读一些旧代码从MSSQL2014转到了MSSQL2008)
SELECT SERVERPROPERTY('productversion'),
SERVERPROPERTY ('productlevel'),
SERVERPROPERTY ('edition'),
@@version
select @@version
--------------------------------------------------------------------------------------------------------------------------------------
1)ODBC配置
Employees是刚配置(MSSQL2008, 64bit, 为转换MySQL表到MSSQL中去)
下面数据源有5个的是2019年配置(当时安装MSSQL2014,,为了BarTender连接Excel文件打印标签用)
2)在MSSQL的SQL Server Management Studio的Query中输入:
EXEC master.dbo.sp_addlinkedserver
@server=N'MYSQL',
@srvproduct=N'MySQL',
@provider=N'MSDASQL',
@provstr=N'DRIVER={MySQL ODBC 8.0 ANSI Driver}; SERVER=127.0.0.1;
DATABASE=Employees; USER=root; PASSWORD=123456; OPTION=3'
//点击上面那个链接时,提示下面信息:
(7303问题,还没找到根本的解决方法,稍后继续...)
TITLE: Microsoft SQL Server Management Studio
------------------------------
Failed to retrieve data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&LinkId=20476
------------------------------
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "MYSQL". (Microsoft SQL Server, Error: 7303)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1600&EvtSrc=MSSQLServer&EvtID=7303&LinkId=20476
3)然后再向表中插入数据插表
select * into pubs.dbo.employees
from openquery(mysql,'select * from employees.employees')
--------------------------------------------------------------------------------------------------------------------------
--在MSSQL中需要Employees这个表的数据集时,这个数据自己可能会经常用到用于实验,在Dos命令提示符下执行:
bcp testdb.dbo.Employees in c:\temp\employees.txt -c -T
testdb是我测试用的DBName,Employees是TableName, in(表示导入数据), 后面是Path, 再就是字符类型,信任连接
--------------------------------------------------------------------------------------------------------------------------