SQL Server的数据导入MySQL数据库方法简介(1)
第一种是安装mysql ODBC,利用sql server的导出功能,选择mysql数据源,进行数据的直接导出,这种方法很简便,但是针对实际应用有很多弊端,最主要体现就是数据类型问题,首先,sql server数据库中的ntext,image等数据类型的数据无法直接写入到mysql数据库中
第一种是安装mysql ODBC,利用sql server的导出功能,选择mysql数据源,进行数据的直接导出,这种方法很简便,但是针对实际应用有很多弊端,最主要体现就是数据类型问题,首先,sql server数据库中的ntext,image等数据类型的数据无法直接写入到mysql数据库中,据说只要稍加改动就可以,可惜偶这只菜鸟还没想到如何改动,其次,因为偶在mysql中的数据库设计中将时间都设成int型(保存的是时间戳),所以在数据导过来后,就会出现冲突,再次,这种方法生成的mysql数据表的字段类型都不很合适,所以此种方法我觉得不能提倡。
第二种是利用php或asp脚本来实现数据的导入功能,这种方法需要编写程序,但灵活性大,操作也不是那么困难,一切都尽在你的掌握之中,现简单介绍一下该方法。前提条件是你的mysql环境已经搭建好了,先建好目标数据库,再将所有的表结构用sql语句生成,现在万事具备,只缺数据了。
可以通过下面的php脚本来实现sql server中mydb数据库的user表中数据向mysql中mydb数据库导入:
$cnx = odbc_connect('web', 'admin', '123456'); //'web'是sqlserver中mydb的数据源名, 'admin'是访问mydb的用户名,'123456'是访问mydb的密码 $cur= odbc_exec( $cnx, 'select * from user' ); //打开sql server中mydb数据库的user表 $num_row=0; $conn=mysql_pconnect("localhost","root","123456"); // 连接mysql @mysql_select_db('mydb',$conn) or die("无法连接到数据库,请与管理员联系!"); //打开mysql的mydb数据库 while( odbc_fetch_row( $cur )) //从sql server的mydb库中的user表逐条取出数据,如果对数据进行选择, 可在前面的select语句中加上条件判断 { $num_row++; $field1 = odbc_result( $cur, 1 ); // 这里的参数i(1,2,3..)指的是记录集中的第i个域, 你可以有所选择地进行选取,fieldi得到对应域的值,然后你可以对fieldi进行操作 $field2 = odbc_result( $cur, 2 ); $field3 = odbc_result( $cur, 3 ); $field4 = odbc_result( $cur, 4 ); $field5 = odbc_result( $cur, 5 ); $field6 = odbc_result( $cur, 6 ); $field5 = timetoint($field5); //这里是对sql server中的datetime类型 的字段进行相应转换处理,转换成我所需要的int型 $querystring = "insert into user (id,name,username,password,recdate) values('$field1','$field2','$field3','$field4','$field5')" ; mysql_query($querystring,$conn); } function timetoint($str){ $arr1=split(" ",$str); $datestr=$arr1[0]; $timestr=$arr1[1]; $arr_date=split("-",$datestr); $arr_time=split(":",$timestr); $year=$arr_date[0]; $month=$arr_date[1]; $day=$arr_date[2]; $hour=$arr_time[0]; $minute=$arr_time[1]; $second=$arr_time[2]; $time_int=mktime($hour,$minute,$second,$month,$day,$year); return $time_int; } ?> Copy after login |
将该段脚本存成sql.php,在服务器上执行,就可以将服务器上sql server中mydb数据库的user表中的数据导入到mysql中mydb数据库的user表中去。其他表的操作与此雷同,就不赘述了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.

MySQL and phpMyAdmin can be effectively managed through the following steps: 1. Create and delete database: Just click in phpMyAdmin to complete. 2. Manage tables: You can create tables, modify structures, and add indexes. 3. Data operation: Supports inserting, updating, deleting data and executing SQL queries. 4. Import and export data: Supports SQL, CSV, XML and other formats. 5. Optimization and monitoring: Use the OPTIMIZETABLE command to optimize tables and use query analyzers and monitoring tools to solve performance problems.

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.
