Home Learn More Purchase Knowledge Base Support Contact

Community Forums

KBPublisher Forums » KBPublisher General discussion

Importing from MySQL

(5 posts)

  1. pax
    Member

    I'm trying to import articles from a mysql database, that is used by wordpress. Exporting the data to csv file format and using the import utility included in KBPublisher. The export itself have been done, but i have some problems with the linebreaks. I tried to export the data with two commands.. :

    select post_title,post_content,post_date into outfile '/tmp/export.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' from wp_posts;

    mysql -u user -ppass wordpressdb -B -e "select post_content,post_title,post_date from wp_posts;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g'; > export.csv

    In both cases, importing into kbpublisher, leaving the field options by default, as them look like corrects. The entire articles are imported in one whole big line :D.
    Can someone help me?

    Cheers,
    Rafael

    Posted 1 year ago #
  2. Andrey
    Administrator

    What OS do you use?
    Try to replace '\n' with '\r\n' or even '\r'.
    It would be helpful if you provide us with an excerpt of .csv file.

    Posted 1 year ago #
  3. pax
    Member

    I tried with this two sample *.csv:

    "Title","Body\r\nBody\r\nBody\r\nBody\r\nBody\r\nBody\r\nBody","2010-02-02 09:09:09"

    And we tried with '\n','\r','\r\n'.
    The result is that all the '\r\n' are changed by spaces and not line breaks.

    We use Debian GNU/Linux 5.0.

    Cheers,
    Rafael

    Posted 1 year ago #
  4. Andrey
    Administrator

    Do you mean that after importing you have article body presented like:
    "Body Body Body Body Body Body Body" ?
    If so, you should replace '\r\n' with HTML line break (due to articles in KBPublisher are stored in HTML format).

    Try this command:

    $ cat file1.csv |sed 's/\\r\\n/<br \/>\\r\\n/g' > file2.csv

    Posted 1 year ago #
  5. pax
    Member

    That's what i'd call focus on the solution not the problem... :) Trying to do an workaround for the missed linebreak and never thought about the <br> tag. Your exact command didn't work, but i used the idea. The linebreak options of the mysql select was related to separate the articles (and not the linebraaks inside the post_content), so i skipped the use of the \n. After the export, i've used the command:

    $ cat file1.csv |sed 's/^$/<br \/>/g' > file2.csv

    This way i get all the blank lines (which disappear during the import), and put a <BR> in there. It worked like a charm.

    Thanks for your support!

    Att,
    Rafael

    Posted 1 year ago #

RSS feed for this topic

Reply

You must log in to post.

© 2008 Double Jade LLC | customer.service@kbpublisher.com