Is sed a solution to this problem for loading data back into mysql db?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is sed a solution to this problem for loading data back into mysql db?
Dear All,
We have back up a table into text file first via the into file method. Then on another server we try to run this command LOAD DATA LOCAL INFILE '/usr/local/backUp.txt' INTO TABLE data1 FIELDS TERMINATED BY ' ' LINES TERMINATED BY '\n'. It works but only able to fill the first column and the rest are all empty. Any solution to this problem? Sample of the data is below.
That's an odd dump. If \n is meant to be a line terminator, why are you
popping lots of \n into the individual rows? And is the original dump from
a linux, a windows or a Mac box?
Dear Tinkster,
The original itself is in linux and now I am backing it back also into linux. Any resolution to this?
Quote:
Originally Posted by Tinkster
That's an odd dump. If \n is meant to be a line terminator, why are you
popping lots of \n into the individual rows? And is the original dump from
a linux, a windows or a Mac box?
Hard to say ... what's the actual table structure you're trying to
push this into? Looking at the file w/ awk, counting columns, the
result isn't promising for any import, no matter what tool you'd
use ....
Dear Tinkster,
I do not cause we generate it via the select into file method which we had no control over the fields either why is like difficult for me to answer as that is the results of mysql?
Quote:
Originally Posted by Tinkster
Hard to say ... what's the actual table structure you're trying to
push this into? Looking at the file w/ awk, counting columns, the
result isn't promising for any import, no matter what tool you'd
use ....
I do not cause we generate it via the select into file method which we had no control over the fields either why is like difficult for me to answer as that is the results of mysql?
Che? Can you please rephrase that?
And can you please stop top-posting? If all you do is quote
my entire post might as well save the precious space, and not
quote at all.
Dear Tinkster,
What I was trying to tell is that the file is output based on select into file so why there are 23/24 fields I also could not answer as we did not build the file manually by ourselves? So what best solution can you suggest?
Unless you've got the orig cmd (and even then) its going to be tricky to say why it is like it is....
So, focussing on the soln, as asked above, tell us what table structure you intend to insert this stuff into and we'll be able to give you some ptrs.
The main thing is to match the data fields you've got with the num of cols in the target table.
Dear All,
I have managed it with some removal of fields and insertion of dummy fields. So looks like ok for now. So future backup for million of records like this what is the best advice when I select into file should I do some delimiters?
I recommend using the methods provided by the DB for such purposes.
"select into" doesn't seem to be good enough. If you can modify the
select to insert delimiters, how come you can't use the appropriate
methods for the database, mysqldump?
I also recommend using mysqldump if moving between MySQL DBs; it'll handle the fiddly bits for you.
If you want to use the other method, you really need to read the relevant docs pages carefully and know your data very well.
A 3rd option for moving data to other formats generally is to write a program (personally I've done a lot with Perl) and create the output exactly as you want it.
Dear All,
Actually I forgot the mention the main reason I used the select into because I did not wanted to dump the whole table but just a data between a date range e.g a particular month. So for that case what is best is it dump or any other mechanism?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.