mysqlimport - Importing text to MySQL: strange format -
I am importing some data from a .txt file into MySQL database tables using mysqlimport. It seems that right (no error message) is imported, but it looks very strange when displayed, and can not be searched as expected.
Here the details are given. The original text file is saved in UTF-8, along with the record (like in the text editor) looks like this: The second area contains line breaks:
< Pre> war-16,52 ~~~~~ Online Advertising About Us ~~~~~ ENDOFRECORD War-16,53 ~~~~~ Online Advertising. About us about us ~~~~~ ENDOFRECORD
The database table in which I am importing is very simple:
+ - ------ + - ------------- + ------ + ----- + --------- + ----- - + | Field | Type | Faucet Key | Default | Extra | + ------- + --------------- + ------ + ----- + --------- + - - ---- + | ID | Varchar (100) | Yes. | Faucet | | Text | Varchar (5000) | Yes. | Faucet | + ------- + --------------- + ------ + ----- + --------- + - < / Code>
When I import a file, here's the command I use:
$ mysqlimport - u root db textfile. Txt - fields-terminated-by = "~~~~~" - -in-terminated-by = "endomethin" - default-character-set = 'UTF 8' db.records_list: records: 18778 deleted: 0 omitted : 0 Alerts: 18787
I see if I then ask MySQL to display the record:
mysql> Choose * from text file; | WAR - 1 6, 5 2 L. O. R. M. I. P. S. U. M. L. O. R. S.T. T. L. O. R. M. M. S S M. M. D. O. L. R. S.T. T. T. T. (Ed.)
It seems like spaces, or some strange encoding extras, being added in text.
And here is a problem with the database query:
mysql> * Select * from the text file where the ID is like "% WAR%";
Nothing returns; Neither add spaces:
mysql> * Select * from the text file, where the ID is like "% WA R%";
Only this command returns anything
mysql> * Choose * from the text file where the ID is like "% W%";
Can someone guess what's going on? I think this would be an encoding problem, but I can not work it
------ UPDATE --------
OK, I have checked the database and connection encoding.
mysql> Show variables like "Character_set_%"; + -------------------------- + ---------------------- ------------------ + | Variable_name | Price | + -------------------------- + ---------------------- ------------------ + | Character_set_quine | Latin 1 | Character_set_connection | Latin 1 | Character_set_database Latin 1 | Character_set_file system | Binary | | Character_sat_resests | Latin 1 | Character_set_services | Latin 1 | Character_set_system | UTF8 | | Character_sets_rate | / Usr / local / mysql / share / mysql / charsets / | + -------------------------- + ---------------------- ------------------ + Sets 8 rows (0.01 seconds) in the set
and show table status
The table is latin1_swedish_ci
.
I have rescanned the text file in "Western (Windows Latin 1)" (using text edit on Snow Leopard) and tried to import it similar to the order above, though I still have the same I also tried again with luck:
- Creating a new table and importing existing files with UTF-8 < Li> Copy & amp; To paste the text into another text file that I have imported correctly before, and tried to import it.
Still amazed at all: ((
As outlined in your duplicate question, make sure that your table and Connection is using both UTF-8, this is one of the common sources of this issue.
Comments
Post a Comment