when I try and run:
mysql -u myUser -pPassword -D myDatabase -h myHost < toInsert.sql
from my ubuntu desktop where myHost is a remote Red Hat server and toInsert.sql contains ’ they show up as ’
How can I resolve this?
Note! ’ is NOT the same as '
When I run toInsert.sql from a windows machine with a mysql gui client I do not have this problem.
Thanks
--default-character-set=utf8 has fixed it
so
mysql -u myUser -pPassword -D myDatabase -h myHost --default-character-set=utf8 < toInsert.sql
thanks for the help!
Sounds like you've got code that's confused about encodings. Define what the encoding of the string data in the database is (I recommend UTF-8, but anything will work so long as you're consistent) and then make sure that all the tools you use with it realize that fact.
And “’” is a “’” when the UTF-8 data bytes are reinterpreted as ISO 8859-1.
There are two places this problem could be:
First, you need to check that the encoding on everything in your database is UTF-8.
If that doesn't fix it, then your database might be correct, but your console is unable to display UTF-8 characters. Pipe the output of a query into a file and view it in something that can display UTF-8 characters and see if it looks correct. If it looks correct, then the problem is your terminal.
Related
I have a serious problem regarding mysqldumps!
When I try to mysqldump my databases MySQL keeps telling me
"GOT ERROR 1300: INVALID UTF8 CHARACTER STRING".
Could you please help me to solve this problem?
Try with additing below options:
-f, --force Continue even if we get an sql-error.
i.e: mysqldump -u root -p database --force > dump.sql
For more options, use: man mysqldump
I'm using the following command to export data from my database to csv:
mysqldump -u root -p -T/home/xxx/stock_dump -t --fields-terminated-by=";" products stock
But the database is in UTF-8 and this command exports UTF-8 characters incorrectly, e.g.
ŻYWIEC ZDRÓJ is ĂÂťYWIEC ZDRĂâJ
How do I export it in the correct UTF-8 format?
Adding --default-character-set=utf8 did not help at all.
Or if it is not possible, how do I postprocess it the easiest way? Can iconv do anything about it?
mysqldump produces UTF-8 encoded dumps unless told otherwise (or unless you use a really, really old version of mysqldump -- anyways, your correct using of --default-character-set=utf8 settles it).
Either your text editor is not recognizing UTF-8 correctly, or the data in the database is already wrongly encoded.
I am new to using mysql. First I connect to my web hosting SSH and then I use the following command to connect to the mysql server:
mysql -u mysqlusername -h server_ip -p
(the server is not localhost, it is a remote server)
Then it prompts for the password, I enter it, and I am connected. I receive a mysql> prompt
Now I am trying to import a sql dump while preserving the charset. I've looked around on the internet and apparently the command to use is
mysql -uUSERNAME -pPASSWORD –default-character-set=utf8 USER_DATABASE < backup.sql
but since I am already connected, I try to issue:
–default-character-set=utf8 USER_DATABASE < backup.sql
but a new line appears to enter a new command instantly and its not possible that the command has been executed because the sql backup is 20 mb. It does not do anything.
I am having encoding issues with my website. The dump is in utf-8, all the special charachters show up as they should when I view the file using notepad, but for some reason as soon as I import the dump using phpmyadmin's import menu, I browse the tables and all the special characters are scrambled. When I access the website the characters are scrambled. I added AddDefaultCharset UTF-8 to htaccess file, but to no avail. This is why I want to try to import the dump using mysql command.
You see there is a command
mysql -u mysqlusername -h server_ip -p
and another one
mysql -uUSERNAME -pPASSWORD –-default-character-set=utf8 USER_DATABASE < backup.sql
Did you try to merge them?
Such as
mysql -u mysqlusername -h server_ip -p –-default-character-set=utf8 USER_DATABASE < backup.sql
?
I'm on a japanese system using xampp. This is the line I use to dump my database.
c:\xampp\mysql\bin>mysqldump.exe -uroot wp_newsja > dump.sql
Then I create a database on another server.
c:\xampp\mysql\bin>mysqladmin -uroot create db
But when I try to execute the sql...
c:\xampp\mysql\bin>mysql -uroot db < dump.sql
... I get the following error.
ERROR at line 145: Unknown command '¥''.
On a japanese computer windows path slashes / are represented with "¥". Which leads me to believe this is an utf8 issue. Maybe there is a way I can mysqldump with some utf8 flag? Thanks for any assistance! The exported sql is here: http://goo.gl/7MPVG - Error at line 145:
edit: Problem solved:
mysql --default-character-set=utf8 db < dump.sql
Sorry if I wasted anyone's time.
mysql --default-character-set=utf8 db < dump.sql
You can add this argument --default-character-set=utf8 in the command:
mysql -u USERNAME -p my_database --default-character-set=utf8 < "C:/My Document Names Have Spaces/my_dump.sql"
I've finally found this solution and it works fine with my new installed WampServer 2.5. I've also tried to add the default character setting in my.ini, but it's useless. Until I've tried the above argument added in my DOS batch file.
My batch file execute the command, like this way:
7zip x -so %1.%2.7z|%mysql% -uxxxx -pyyyyy %2 --default-character-set=utf8
For example, the 7zip filename is 20141231.google.7z, which contains "google.sql", and the database name is google
My backup process on Linux system was a 7zip compressed. In Winodws, I used an automatic batch file to restore the same contents, so that I can share the same database in my biz trip and work offline from the server.
Hope this method is helpful to you.
php code:
exec('mysqldump --opt --compress --host='.DB_HOST.' --user='.DB_USER.' --password='.DB_PASS.' '.DB_NAME.' > file.sql');
some characters are not being exported as they are in the DB. For example "ñ" becomes "ñ" -- am i missing a parameter in the mysqldump instruction? BTW, the DB is utf8. thanks!
See this question: How to keep special characters when running ./mysqldump?
Try adding the switch: --default-character-set=UTF8