Home Database Mysql Tutorial MySQL数据导入导出方法与工具介绍二_MySQL

MySQL数据导入导出方法与工具介绍二_MySQL

Jun 01, 2016 pm 02:12 PM
introduce Order import tool data database method

mysql管理工具


  批处理是一种非交互式运行mysql程序的方法,如同您在mysql中使用的命令一样,你仍然将使用这些命令。
  
  为了实现批处理,您重定向一个文件到mysql程序中,首先我们需要一个文本文件,这个文本文件包含有与我们在mysql中输入的命令相同的文本。
  比如我们要插入一些数据,使用包含下面文本的文件(文件名为New_Data.sql,当然我们也可以取名为New_Data.txt及任何其他的合法名字,并不一定要以后缀sql结尾):
  USE Meet_A_Geek;
  INSERT INTO Customers (Customer_ID, Last_Name) VALUES(NULL, "Block");
  INSERT INTO Customers (Customer_ID, Last_Name) VALUES(NULL, "Newton");
  INSERT INTO Customers (Customer_ID, Last_Name) VALUES(NULL, "Simmons");
  注意上面的这些句子的语法都必须是正确的,并且每个句子以分号结束。
  上面的USE命令选择数据库,INSERT命令插入数据。
  
  下面我们要把上面的文件导入到数据库中,导入之前要确认数据库已经在运行,即是mysqld进程(或者说服务,Windows NT下面称为”服务“,unix下面为”进程“)已经在运行。
  然后运行下面的命令:
  bin/mysql –p   接着按提示输入密码,如果上面的文件中的语句没有错误,那么这些数据就被导入到了数据库中。
  
  命令行中使用LOAD DATA INFILE 从文件中导入数据到数据库:
  现在您可能会问自己,"究竟为什么我要输入所有的这些SQL语句到文件中,然后通过程序运行它们呢?”
  这样看起来好像需要大量的工作。很好,你这样想很可能就对了。但是假如你有从所有这些命令中产生的log记录呢?现在这样就很棒,嗯,大多数数据库都会自动产生数据库中的事件记录的log。而大部分log都包含有用过的原始的SQL命令。因此,如果您不能从您现在的数据库中导出数据到新的mysql数据库中使用,那么您可以使用log和mysql的批处理特性,来快速且方便地导入您地数据。当然,这样就省去了打字的麻烦。
  
  LOAD DATA INFILE
  这是我们要介绍的最后一个导入数据到MySQL数据库中的方法。这个命令与mysqlimport非常相似,但这个方法可以在mysql命令行中使用。也就是说您可以在所有使用API的程序中使用这个命令。使用这种方法,您就可以在应用程序中导入您想要导入的数据。
  
  使用这个命令之前,mysqld进程(服务)必须已经在运行。
  启动mysql命令行:
  bin/mysql –p
  按提示输入密码,成功进入mysql命令行之后,输入下面的命令:
  USE Meet_A_Geek;
  LOAD DATA INFILE "/home/mark/data.sql" INTO TABLE Orders;
  简单的讲,这样将会把文件data.sql中的内容导入到表Orders中,如mysqlimport工具一样,这个命令也有一些可以选择的参数。比如您需要把自己的电脑上的数据导入到远程的数据库服务器中,您可以使用下面的命令:
  LOAD DATA LOCAL INFILE "C:\MyDocs\SQL.txt" INTO TABLE Orders;
  
  上面的LOCAL参数表示文件是本地的文件,服务器是您所登陆的服务器。
  这样就省去了使用ftp来上传文件到服务器,MySQL替你完成了.
  您也可以设置插入语句的优先级,如果您要把它标记为低优先级(LOW_PRIORITY),那么MySQL将会等到没有其他人读这个表的时候,才把插入数据。可以使用如下的命令:
  LOAD DATA LOW_PRIORITY INFILE "/home/mark/data.sql" INTO TABLE Orders;
  
  您也可以指定是否在插入数据的时候,取代或者忽略文件与数据表中重复的键值。替代重复的键值的语法:
  LOAD DATA LOW_PRIORITY INFILE "/home/mark/data.sql" REPLACE INTO TABLE Orders;
  上面的句子看起来有点笨拙,但却把关键字放在了让您的剖析器可以理解的地方。
  
  下面的一对选项描述了文件的记录格式,这些选项也是在mysqlimport工具中可以用的。他们在这里看起来有点不同。首先,要用到FIELDS关键字,如果用到这个关键字,MySQL剖析器希望看到至少有下面的一个选项:
  TERMINATED BY character
  ENCLOSED BY character
  ESCAPED BY character
  这些关键字与它们的参数跟mysqlimport中的用法是一样的. The
  TERMINATED BY 描述字段的分隔符,默认情况下是tab字符(\t)
  ENCLOSED BY描述的是字段的括起字符。比方以引号括起每一个字段。
  ESCAPED BY 描述的转义字符。默认的是反些杠(backslash:\ ).
  下面仍然使用前面的mysqlimport命令的例子,用LOAD DATA INFILE语句把同样的文件导入到数据库中:
  LOAD DATA INFILE "/home/mark/Orders.txt" REPLACE INTO TABLE Orders FIELDS TERMINATED BY ',' ENCLOSED BY '"';
  
  LOAD DATA INFILE语句中有一个mysqlimport工具中没有特点:
  LOAD DATA INFILE 可以按指定的列把文件导入到数据库中。
  当我们要把数据的一部分内容导入的时候,这个特点就很重要。比方说,我们要从Access数据库升级到MySQL数据库的时候,需要加入一些栏目(列/字段/field)到MySQL数据库中,以适应一些额外的需要。
  这个时候,我们的Access数据库中的数据仍然是可用的,但是因为这些数据的栏目(field)与MySQL中的不再匹配,因此而无法再使用mysqlimport工具。尽管如此,我们仍然可以使用LOAD DATA INFILE,下面的例子显示了如何向指定的栏目(field)中导入数据:
  LOAD DATA INFILE "/home/Order.txt" INTO TABLE Orders(Order_Number, Order_Date, Customer_ID);
  
  如您所见,我们可以指定需要的栏目(fields)。这些指定的字段依然是以括号括起,由逗号分隔的,如果您遗漏了其中任何一个,MySQL将会提醒您
  
  Importing Data from Microsoft Access (从Access中导入数据,略)
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 尊渡假赌尊渡假赌尊渡假赌

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
1664
14
PHP Tutorial
1269
29
C# Tutorial
1248
24
What kind of software is a digital currency app? Top 10 Apps for Digital Currencies in the World What kind of software is a digital currency app? Top 10 Apps for Digital Currencies in the World Apr 30, 2025 pm 07:06 PM

With the popularization and development of digital currency, more and more people are beginning to pay attention to and use digital currency apps. These applications provide users with a convenient way to manage and trade digital assets. So, what kind of software is a digital currency app? Let us have an in-depth understanding and take stock of the top ten digital currency apps in the world.

Quantitative Exchange Ranking 2025 Top 10 Recommendations for Digital Currency Quantitative Trading APPs Quantitative Exchange Ranking 2025 Top 10 Recommendations for Digital Currency Quantitative Trading APPs Apr 30, 2025 pm 07:24 PM

The built-in quantization tools on the exchange include: 1. Binance: Provides Binance Futures quantitative module, low handling fees, and supports AI-assisted transactions. 2. OKX (Ouyi): Supports multi-account management and intelligent order routing, and provides institutional-level risk control. The independent quantitative strategy platforms include: 3. 3Commas: drag-and-drop strategy generator, suitable for multi-platform hedging arbitrage. 4. Quadency: Professional-level algorithm strategy library, supporting customized risk thresholds. 5. Pionex: Built-in 16 preset strategy, low transaction fee. Vertical domain tools include: 6. Cryptohopper: cloud-based quantitative platform, supporting 150 technical indicators. 7. Bitsgap:

Is the digital currency app formal? Top 10 formal and legal virtual currency trading apps in the world Is the digital currency app formal? Top 10 formal and legal virtual currency trading apps in the world Apr 30, 2025 pm 07:09 PM

Recommended cryptocurrency trading platforms include: 1. Binance: the world's largest trading volume, supports 1,400 currencies, FCA and MAS certification. 2. OKX: Strong technical strength, supports 400 currencies, approved by the Hong Kong Securities Regulatory Commission. 3. Coinbase: The largest compliance platform in the United States, suitable for beginners, SEC and FinCEN supervision. 4. Kraken: a veteran European brand, ISO 27001 certified, holds a US MSB and UK FCA license. 5. Gate.io: The most complete currency (800), low transaction fees, and obtained a license from multiple countries. 6. Huobi Global: an old platform that provides a variety of services, and holds Japanese FSA and Hong Kong TCSP licenses. 7. KuCoin

What is the core difference between Huobi's previous Huoxin and OKX's current pay? What is the core difference between Huobi's previous Huoxin and OKX's current pay? Apr 30, 2025 pm 06:33 PM

Neither Huoxin nor OKX Pay directly supports fiat currency payment. Huoxin is mainly used for digital asset management and transactions, and users need to exchange fiat currency through the Huobi Exchange; OKX Pay focuses on digital asset payment and transfer, and users need to exchange fiat currency through the OKX platform.

Is there a future for digital currency apps? Apple mobile digital currency trading platform app download TOP10 Is there a future for digital currency apps? Apple mobile digital currency trading platform app download TOP10 Apr 30, 2025 pm 07:00 PM

The prospects of digital currency apps are broad, which are specifically reflected in: 1. Technology innovation-driven function upgrades, improving user experience through the integration of DeFi and NFT and AI and big data applications; 2. Regulatory compliance trends, global framework improvements and stricter requirements for AML and KYC; 3. Function diversification and service expansion, integrating lending, financial management and other services and optimizing user experience; 4. User base and global expansion, and the user scale is expected to exceed 1 billion in 2025.

How to download the Hong Kong Digital Currency Exchange app? The top ten digital currency exchange apps are included How to download the Hong Kong Digital Currency Exchange app? The top ten digital currency exchange apps are included Apr 30, 2025 pm 07:12 PM

The methods to download the Hong Kong Digital Currency Exchange APP include: 1. Select a compliant platform, such as OSL, HashKey or Binance HK, etc.; 2. Download through official channels, iOS users download on the App Store, Android users download through Google Play or official website; 3. Register and verify their identity, use Hong Kong mobile phone number or email address to upload identity and address certificates; 4. Set security measures, enable two-factor authentication and regularly check account activities.

What are the three giants in the currency circle? Top 10 Recommended Virtual Currency Main Exchange APPs What are the three giants in the currency circle? Top 10 Recommended Virtual Currency Main Exchange APPs Apr 30, 2025 pm 06:27 PM

In the currency circle, the so-called Big Three usually refers to the three most influential and widely used cryptocurrencies. These cryptocurrencies have a significant role in the market and have performed well in terms of transaction volume and market capitalization. At the same time, the mainstream virtual currency exchange APP is also an important tool for investors and traders to conduct cryptocurrency trading. This article will introduce in detail the three giants in the currency circle and the top ten mainstream virtual currency exchange APPs recommended.

Funding fees for perpetual positions Funding fees for perpetual positions Apr 30, 2025 pm 06:42 PM

The funding fee for a perpetual position is the fee that the holder needs to pay or charge in perpetual contract trading. It is usually calculated every eight hours, affecting the trader's profit and loss and strategy.

See all articles