Microsoft Word - Sam's Teach Yourself MySQL in 21 Days - SAMS.doc

(singke) #1
Figure 8.11 Output from DESCRIBE Orders.


  1. The next step is where you actually import the data into the database. Enter the
    following statement at the command line:
    9. LOAD DATA LOCAL INFILE "E:\OrdersImport.txt"
    10. INTO TABLE Orders
    11. FIELDS
    12. TERMINATED BY ','
    13. ENCLOSED BY '"'
    14. (Order_ID, Customer_ID, Order_Date, Required_Date,
    Ship_Date);


This should bring all your data in successfully.

Database Transfer Tools


As you can see, MySQL has many built-in tools to help transfer data from one database to another. MySQL
is also very accepting. Even though it may not use certain features other databases have, such as FOREIGN
KEYS, MySQL will not generate an error if it comes across these while importing data. This is because
MySQL developers wanted it to be extremely flexible when migrating. To accomplish this, they had to allow
for these anomalies.


Because MySQL is from the realm of open source, many people have contributed programs or other
useful tools to help work with MySQL. Some of these are GUI interfaces, import wizards, and API
wrappers. These tools, along with the ones you can create, are valuable assets to any MySQL DBA.
The MySQL Web site and the CD-ROM that comes with this book have some very useful tools. Explore
them and put them to use. There is a very helpful Access export tool called exportsql.txt It takes
the schema and the data from the database and exports them to a text file. The sister script,
importsql, does the same thing in reverse, taking a MySQL database and converting it to Access.

Methods of Exporting Data


You can see that MySQL has a rich set of importing utilities. But this is only half of a data transfer. The other
half is pulling data out of MySQL. There are a number of reasons for exporting data.
One important reason is for backing up your database. The price of data is always high, and it pays to
take care of it. Regular backups can help prevent the loss of precious data. Day 19, "Administrating
MySQL," covers the back up process completely. For now, know that backing up your data is one
reason for exporting it.


Another reason you may want to export your data is to share it. In the ever growing world of information
technology, sharing data is becoming more and more common. For example, Macmillan USA maintains
a huge database of potential books. This database is shared among the book stores so they know what
books will be published soon. Hospitals are moving closer and closer to a paperless medical record that
will follow you where ever you go. The world is getting smaller, and information is being shared more
and more and every year.

There are a number of different ways to export data. They are all very similar to importing data,
because, after all, it is all just a matter of perspective. Data that is being exported from one database is
Free download pdf