mysql
, The Command-line Tool
mysqladmin
, Administrating a MySQL Server
mysqlbinlog
, Executing the queries from a binary log
mysqlcheck
for Table Maintenance and Crash Recovery
mysqldump
, Dumping Table Structure and Data
mysqlhotcopy
, Copying MySQL Databases and Tables
mysqlimport
, Importing Data from Text Files
mysqlshow
, Showing Databases, Tables, and Columns
mysql_config
, Get compile options for compiling clients
perror
, Explaining Error Codes
mysqlimport
, Importing Data from Text Files
mysqlimport
provides a command-line interface to the LOAD DATA
INFILE
SQL statement. Most options to mysqlimport
correspond
directly to the same options to LOAD DATA INFILE
.
See section 6.4.9 LOAD DATA INFILE
Syntax.
mysqlimport
is invoked like this:
shell> mysqlimport [options] database textfile1 [textfile2 ...]
For each text file named on the command-line,
mysqlimport
strips any extension from the filename and uses the result
to determine which table to import the file's contents into. For example,
files named `patient.txt', `patient.text', and `patient' would
all be imported into a table named patient
.
mysqlimport
supports the following options:
-c, --columns=...
LOAD DATA INFILE
command,
which is then passed to MySQL. See section 6.4.9 LOAD DATA INFILE
Syntax.
-C, --compress
-#, --debug[=option_string]
-d, --delete
--fields-terminated-by=...
--fields-enclosed-by=...
--fields-optionally-enclosed-by=...
--fields-escaped-by=...
--lines-terminated-by=...
LOAD DATA INFILE
. See section 6.4.9 LOAD DATA INFILE
Syntax.
-f, --force
--force
,
mysqlimport
exits if a table doesn't exist.
--help
-h host_name, --host=host_name
localhost
.
-i, --ignore
--replace
option.
-l, --lock-tables
-L, --local
localhost
(which is the default host).
-pyour_pass, --password[=your_pass]
mysqlimport
you will be prompted for a password.
-P port_num, --port=port_num
--protocol=(TCP | SOCKET | PIPE | MEMORY)
-r, --replace
--replace
and --ignore
options control handling of input
records that duplicate existing records on unique key values. If you specify
--replace
, new rows replace existing rows that have the same unique key
value. If you specify --ignore
, input rows that duplicate an existing
row on a unique key value are skipped. If you don't specify either option, an
error occurs when a duplicate key value is found, and the rest of the text
file is ignored.
-s, --silent
-S /path/to/socket, --socket=/path/to/socket
localhost
(which is the
default host).
-u user_name, --user=user_name
-v, --verbose
-V, --version
Here is a sample run using mysqlimport
:
$ mysql --version mysql Ver 9.33 Distrib 3.22.25, for pc-linux-gnu (i686) $ uname -a Linux xxx.com 2.2.5-15 #1 Mon Apr 19 22:21:09 EDT 1999 i586 unknown $ mysql -e 'CREATE TABLE imptest(id INT, n VARCHAR(30))' test $ ed a 100 Max Sydow 101 Count Dracula . w imptest.txt 32 q $ od -c imptest.txt 0000000 1 0 0 \t M a x S y d o w \n 1 0 0000020 1 \t C o u n t D r a c u l a \n 0000040 $ mysqlimport --local test imptest.txt test.imptest: Records: 2 Deleted: 0 Skipped: 0 Warnings: 0 $ mysql -e 'SELECT * FROM imptest' test +------+---------------+ | id | n | +------+---------------+ | 100 | Max Sydow | | 101 | Count Dracula | +------+---------------+
Posted by Tom Reinertson on Friday May 17 2002, @6:24am | [Delete] [Edit] |
Keep in mind that your imported text file should
have some value for empty fields. I regularly
build tables using msqlimport to import
tab-delimited text files. My tables contain
integer fields, some of which are
auto_incremented and some are not. MYSQL will
let you represent empty fields as null text
strings, i.e., two tab characters back-to-back,
but I found this increments the warning count.
To solve this problem you must use some value
for empty fields. Since auto_increment fields
use 0 or NULL, one would think, incorrectly,
that you could use 0 or \N to represent a null
value in the import text file. You must 0 for
an auto_increment field. Using \N increments
the warning count. You should use \N for other
numeric fields where you want a null value.
This problem is especially perplexing because of
MySQL's inability to report the text of a
warning. It only reports a warning count.
Posted by Murali Mohan on Tuesday November 5 2002, @10:58pm | [Delete] [Edit] |
Before you invoke mysqlimport command with
appropriate options, please check that the 'FILE'
privilege is granted to you.
I wasted time facing the 'Access Denied on
table_name' error
because of the same.
Posted by Subburaj Palanichamy on Wednesday January 29 2003, @3:51am | [Delete] [Edit] |
Mysqlimport - access_to_mysql.txt - Usage - reg.
While converting the data from Microsoft Access database to Mysql, I have used the access_to_mysql.txt tool. In my database, some of the tables were were linked with another microsoft access database for which password has been set. Hence while converting the data, it displayed an error.
To over come this, I opened the database which has the linked table and removed the password set for that database.
Once password is removed, all the tables and data was successfully transferred to C:\temp\mysqldump.txt file.
Posted by Gael Chabirand on Tuesday May 13 2003, @11:32am | [Delete] [Edit] |
It could be a great idea to allow to specify a destination table for the import.
It also could be great to support the * like:
shell>mysqlimport --table Operator User*.*
Which could import into the table Operator, the content of the files UserSAP.usr and UserUNIX.txt...
Gael.