0

Thanks for viewing this. I need a little bit of help for this project that I am working on with MySql.

For part of the project I need to load a few things into a MySql database which I have up and running.

The info that I need, for each column in the table Documentation, is stored into text files on my hard drive.

For example, one column in the documentation table is "ports" so I have a ports.txt file on my computer with a bunch of port numbers and so on.

I tried to run this mysql script through phpMyAdmin which was

LOAD DATA INFILE 'C:\\ports.txt" INTO TABLE `Documentation`(`ports`). 

It ran successfully so I went to do the other load data i needed which was

LOAD DATA INFILE 'C:\\vlan.txt' INTO TABLE `Documentation` (`vlans`)

This also completed successfully, but it added all the rows to the vlan column AFTER the last entry to the port column.

Why did this happen? Is there anything I can do to fix this? Thanks

0

1 Answer 1

1

Why did this happen?

LOAD DATA inserts new rows into the specified table; it doesn't update existing rows.

Is there anything I can do to fix this?

It's important to understand that MySQL doesn't guarantee that tables will be kept in any particular order. So, after your first LOAD, the order in which the data were inserted may be lost & forgotten - therefore, one would typically relate such data prior to importing it (e.g. as columns of the same record within a single CSV file).

You could LOAD your data into temporary tables that each have an AUTO_INCREMENT column and hope that such auto-incremented identifiers remain aligned between the two tables (MySQL makes absolutely no guarantee of this, but in your case you should find that each record is numbered sequentially from 1); once there, you could perform a query along the following lines:

INSERT INTO Documentation SELECT port, vlan FROM t_Ports JOIN t_Vlan USING (id);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.