Home Database Mysql Tutorial SQLServer导出数据到MySQL实例介绍

SQLServer导出数据到MySQL实例介绍

Jun 07, 2016 pm 04:17 PM
mysql sqlserver introduce Example Export data

1从SQLServer导出数据 执行BCP: bcp ... queryout F:test.txt -c S1.2.3.4 -Usa -P1111 命令参数含义: (1) 导入。 这个动作使用in命令完成,后面跟需要导入的文件名。 (2) 导出。 这个动作使用out命令完成,后面跟需要导出的文件名。 (3) 使用SQL语句导出

1从SQLServer导出数据
执行BCP:
bcp "..." queryout "F:test.txt" -c –S1.2.3.4 -Usa -P1111
命令参数含义:
(1) 导入。
这个动作使用in命令完成,后面跟需要导入的文件名。
(2) 导出。
这个动作使用out命令完成,后面跟需要导出的文件名。
(3) 使用SQL语句导出。
这个动作使用queryout命令完成,它跟out类似,只是数据源不是表或视图名,而是SQL语句。
(4) 导出格式文件。
这个动作使用format命令完成,后而跟格式文件名。
下面介绍一些常用的选项:
-f format_file
format_file表示格式文件名。这个选项依赖于上述的动作,如果使用的是in或out,format_file表示已经存在的格式文件,如果使用的是format则表示是要生成的格式文件。
-x
这个选项要和-f format_file配合使用,以便生成xml格式的格式文件。
-F first_row
指定从被导出表的哪一行导出,或从被导入文件的哪一行导入。
-L last_row
指定被导出表要导到哪一行结束,或从被导入文件导数据时,导到哪一行结束。
-c
使用char类型做为存储类型,没有前缀且以"/t"做为字段分割符,以"/n"做为行分割符。
-w
和-c类似,只是当使用Unicode字符集拷贝数据时使用,且以nchar做为存储类型。
-t field_term
指定字符分割符,,默认是"/t"。
-r row_term
指定行分割符,默认是"/n"。
-S server_name[ /instance_name]
指定要连接的SQL Server服务器的实例,如果未指定此选项,BCP连接本机的SQL Server默认实例。如果要连接某台机器上的默认实例,只需要指定机器名即可。
-U login_id
指定连接SQL Sever的用户名。
-P password
指定连接SQL Server的用户名密码。
-T
指定BCP使用信任连接登录SQL Server。如果未指定-T,必须指定-U和-P。
-k
指定空列使用null值插入,而不是这列的默认值。
2导入数据到MySQL
执行Load Data命令:
load data local infile "F:/test.txt" into table table1character set gbk;
命令参数含义:
load data [low_priority] [local] infile 'file_name txt' [replace |ignore]
into table tbl_name
[fields
[terminated by't']
[OPTIONALLY] enclosed by '']
[escaped by'' ]]
[lines terminated by'n']
[ignore number lines]
[(col_name, )]
2.1 Low_priority
如果你指定关键词low_priority,那么MySQL将会等到没有其他人读这个表的时候,才把插入数据。
2.2 Local
如果指定local关键词,则表明从客户主机读文件。如果local没指定,文件必须位于服务器上。
2.3 Replace & Ignore
replace 和ignore关键词控制对现有的唯一键记录的重复的处理。如果你指定replace,新行将代替有相同的唯一键值的现有行。如果你指定ignore,跳 过有唯一键的现有行的重复行的输入。如果你不指定任何一个选项,当找到重复键时,出现一个错误,并且文本文件的余下部分被忽略。
2.4分隔符
terminated by描述字段的分隔符,默认情况下是tab字符(t)
enclosed by描述的是字段的括起字符。
escaped by描述的转义字符。默认的是反斜杠(backslash:)
lines 关键字指定了每条记录的分隔符默认为'n'即为换行符
2.5导入部分列
load data infile可以按指定的列把文件导入到数据库中。当我们要把数据的一部分内容导入的时候,,需要加入一些栏目(列/字段/field)到MySQL数据库中,以适应一些额外的需要。比方说,我们要从Access数据库升级到MySQL数据库的时候
下面的例子显示了如何向指定的栏目(field)中导入数据:
load data infile "/home/Ordertxt" into table Orders(Order_Number, Order_Date, Customer_ID);
2.6相对&绝对路径
(1)如果给出一个绝对路径名,服务器使用该路径名。
(2)如果给出一个有一个或多个前置部件的相对路径名,服务器相对服务器的数据目录搜索文件。
(3)如果给出一个没有前置部件的一个文件名,服务器在当前数据库的数据库目录寻找文件。
例如: /myfile txt”给出的文件是从服务器的数据目录读取,而作为“myfile txt”给出的一个文件是从当前数据库的数据库目录下读取。
2.7字符集
character set gbk指定字符集为gbk,与文件的编码格式(ANSI)保持一致。否则中文数据导入后可能变为乱码。
2.8灵活导入
可以在导入的同时,插入一些其他列:
load data local infile "F:/test.txt"into table table1 set pin='zs',create_date=current_timestamp;
3常见问题
3.1无法运行Load Data命令
执行load data localinfile时报错:
The used command is not allowed with this MySQL version
解决方法是:启动mysql客户端是加上--local-infile=1参数
$ mysql --local-infile=1 –uroot –p123 –h 127.0.0.1
3.2用BCP导出UTF-8格式
解决方法是加上-C选项:
$ bcp "query sql…" queryout "F:test.txt" -c -C65001–S1.2.3.4 -Usa -P1111

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1272
29
C# Tutorial
1251
24
Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

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.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Apr 18, 2025 am 08:42 AM

When developing an e-commerce website using Thelia, I encountered a tricky problem: MySQL mode is not set properly, causing some features to not function properly. After some exploration, I found a module called TheliaMySQLModesChecker, which is able to automatically fix the MySQL pattern required by Thelia, completely solving my troubles.

MySQL: Structured Data and Relational Databases MySQL: Structured Data and Relational Databases Apr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities Explained MySQL: Key Features and Capabilities Explained Apr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

See all articles