Using mysqlimport where the filename is different from the table name
Asked Answered
A

4

14

I've been playing with mysqlimport and I've run into the restriction where the filename has to be the same as the table name. Is there any way to work round this?

I can't rename the file as it is used by other processes and I don't want to copy the file as there will be many of them, some being very large.

I want to use mysqlimport not LOAD INFILE.

EDIT: Unfortunately this needs to run on windows so no tricks with symbolic links I'm afraid.

Arty answered 24/3, 2010 at 14:41 Comment(3)
Why don't you want to use LOAD DATA INFILE, when it is the same as what mysqlimport does and it allows you to specify a different table name for a given input file?Upu
I'm using Java/JDBC and invoking the LOAD INFILE doesn't seem to produce any error when there is a problem loading the file in some situations. You get warnings displayed if you run it through the Workbench but the JDBC driver gives me nothing back.Arty
mysqlimport should allow a parameter to set a different table name, this is a basic feature...Figurehead
M
13

You didn't say what platform you are on. On unix you can create a symbolic link to the file:

ln -s filename.txt tablename.txt

Then use that in the mysqlimport command.

But mysqlimport is just a command line interface to LOAD INFILE so you could also do this on the command line:

mysql -e "load data infile 'filename' into table TBL_NAME" dbname
Micrometer answered 24/3, 2010 at 14:50 Comment(2)
you can still use mysql on windows with the same syntax.. symlinking the files is a bit of a weird way of doing it.Nims
They are not technically the same, when using mysql, the filename needs to be on the MySQL server inside the secure_priv_dir. This might be a problem for platforms like Amazon RDS where you are not allowed to upload files to the serverUntouched
E
1

mysqlimport uses the filename to determine the name of the table into which the data should be loaded. The program does this by stripping off any filename extension (the last period and anything following it); the result is then used as the table name. For example, mysqlimport treats a file named City.txt or City.dat as input to be loaded into a table named City.

Exiguous answered 7/8, 2015 at 3:45 Comment(0)
G
0

Have you tried using the alias command, assuming you are on a Linux system?

Gamboge answered 24/3, 2010 at 14:45 Comment(0)
H
0

Just create a symbolic link:

ln -s /tmp/real_file.txt /tmp/your_table_name.txt
Handgun answered 24/3, 2010 at 14:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.