The option determines the statement’s security requirements as well as whether the source text file is located on the client system or the server hosting the MySQL instance: When you create a LOAD DATA statement, you can include the LOCAL option as part of the statement definition. However, there are a few other issues to be aware of in order to import data, starting with the LOCAL option. As with any SQL statement in MySQL, you must have been granted the privileges necessary to carry out your operations (a topic beyond the scope of this article). Often the most difficult part of the operation is setting up your environment to ensure that it will allow you to run a LOAD DATA statement and import the data into the target table. Importing data from a text file into a MySQL database is in itself a fairly straightforward process. The last section of the article-“Appendix: Preparing your MySQL environment”-provides information about how I set up my system and includes a SQL script for creating the database and table on which the examples are based. Note: The examples in this article are based on a local instance of MySQL that hosts a very simple database and table. Each example retrieves data from a file on the local system and adds the data to the manufacturers table in the travel database, which you’ve seen in previous articles in this series. Although the examples are fairly basic, they demonstrate the fundamental components that go into a LOAD DATA statement and some of the issues you might run up against along the way. In this article, I show how to use the LOAD DATA statement to add data from comma-separated values (CSV) files and other plain text files. To help with the import process, MySQL provides the LOAD DATA statement, which reads rows from a text file and inserts them into the target table. The files might be used to add lookup data, support test and development environments, populate new MySQL instances, load data from regular feeds, or in other ways support their operations. To see all of the items in the series, click here.ĭatabase and development teams often load data from plain text files into their MySQL databases. This article is part of Robert Sheldon's continuing series on Learning MySQL.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |