MySQL removes line breaks and carriage returns from fields

Source: Internet
Author: User

UPDATE SMS_PROVINCE set provincename = REPLACE (PROVINCENAME, CHAR (10), ''), CHAR (13 ),'');

Environment: RHEL5 + MySQL

Solution:

UPDATE tablename SET field = REPLACE (field, CHAR (10), "), CHAR (13 ),");

Char (10): line feed

Char (13): Carriage Return

Cause:

You can use either of the following methods to generate an excel report:

1) manually generate

Export The data in the table to generate a CSV file.

Use mysqldump to export data

# Mysqldump-u xxx-p -- tab =/tmp/-- fields-terminated-by = "#" DBName TBName

The tbname.txt file will be generated in the tmpdirectory.

Import the generated txt file in EXCEL

2) directly generate a csv file

Mysqldump-u samu-p-T -- fields-terminated-by = "," -- fields-enclosed-by = ""

-- Lines-terminated-by = "\ n" -- fields-escaped-by = "" test Customer

Or:

Mysqldump-u samu-p -- tab =/tmp/-- fields-terminated-by = "," -- fields-enclosed-by = ""

-- Lines-terminated-by = "\ n" -- fields-escaped-by = "" test Customer

However, no matter which method is used, if a column in the table contains a carriage return or line feed,

The generated CSV file or excel file will split the original line of data into two rows.

Because CSV or excel is imported, the number of data entries is determined by the Data row.

Therefore, you must replace the carriage return or line break in the field before this.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.