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

(singke) #1
can perform. Day 11 introduces you to MySQL table locks and assorted keys. The week ends with a
series of chapters—Day 12, "How to Get to the Data—Database Interfaces," Day 13, "How to Use
MyODBC," and Day 14, "The Perl Database Interface"—that deal with building programmatic interfaces
in your MySQL database.

Again, a lot of information is going to be presented to you. Spend some time looking at the examples
and doing the exercises and everything will become clear to you.

Day 8: Populating the Database


Overview


Now that you have designed and created your database, you're ready to put some data into it. You could
enter all your data from the command line, but that could be a little tedious, not to mention a waste of time.
MySQL offers many ways of importing and exporting data. Let's face it, the most important part of a
database is the data, and MySQL has provided many tools for helping with the movement of data in and out
of the database.


There are many ways to populate your database. There are also many tools available to help you. The
CD-ROM contains some of these third-party tools. Today, you will learn
ƒ Some techniques to import data
ƒ How to import data from a Microsoft Access database
ƒ How to export data from a MySQL database

Methods of Importing Data


There are many reasons to learn how to import data from one database to another. One reason may be
because you have outgrown your current database. You need to change database products, but you don't
want to loose all the data you have collected over the years. Another reason may be because you don't want
to enter in all your data through the command line. This can be a very boring and time-consuming process
and can be very error prone. A final reason could be that you are synchronizing your database with another
database. The data needs to be transferred, but the databases do not share the same file formats. These
are valid reasons for you to understand the many different ways MySQL can aid you in the importation of
data.


There are many different ways to import data from an existing database to another database. The most
common way of doing it is the Bulk Copy Protocol (BCP). It is an extremely fast way of importing text-
based data into an existing data structure. Many databases on the market use this protocol, namely
Microsoft SQL Server and Sybase Adaptive Server.

Another common way to import data is through a file conversion process. A file that is written in one
format in one database is converted to another format for the new database. You can see this in action
when you try to import data into MS Access. The import tool lets you select a file type. After you have
selected your file type, it is automatically converted to fit into the new MS Access type. Old Dbase files
are converted in this way as well.

Yet another way is to export the data from one database into a format that the other database can read.
Comma-delimited files are a prime example. One database exports all of its data into a comma-
delimited text file, and the other database reads it in. This is similar to the way BCP works but on a more
rudimentary level.
The newest way to transfer data (that's really what we're talking about here) is with Extensible Markup
Language (XML). It's a language that resembles Hypertext Markup Language but is more robust. It
allows programmers to create their own mark up tags, giving developers more freedom than HTML. It
offers a way to transfer data across networks easily and reliably. New releases of all the major
databases are incorporating this new technology in some way. (For more information on XML, read
Sams Teach Yourself XML in 21 Days The developers of MySQL believe that parsing in any way should
be done on a level other than the database level. This makes sense. It allows the database to be free of
overhead, making it faster and giving the power of choice to the programmer. Programmers are not
limited in which format they must output their data—they can simply parse what ever goes in or out of
their databases with their own programs.
Free download pdf