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
Related
For a very long time i was suffering form the Latin-1 encoding in My Django web application DB causing this error when trying to select a matching string using LIKE :
-- UnicodeEncodeError:'latin-1' codec can't encode character--
i've tried every solution from setting (charset='utf8') in the connection to applying cursor.execute("set names 'utf8'") before my actual query but nothing seams to work.
Until i came across this blog post: https://www.whitesmith.co/blog/latin1-to-utf8/
about the encoding problem and it is the same problem that i have because when i looked in phpMyAdmin a saw that by default my DB i Latin-1 encoding:
chatbot_brain=>utf8_general_ci
information_schema=>utf8_general_ci
Total: 2=> latin1_swedish_ci
So, the solution is to dump the DB and change the description in the schema file:
# Login into your future database host to create a new database with an UTF-8 charset
$ mysql -h FUTURE_HOST -u FUTURE_USER -p
mysql> CREATE DATABASE `FUTURE_DB` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
# Flush the current database schema on the future host, replacing all CHARSET=latin1 occurrences along the way
mysqldump -h CURRENT_HOST -u CURRENT_USER -p CURRENT_DB --no-data --skip-set-charset --default-character-set=latin1 \
| sed 's/CHARSET=latin1/CHARSET=utf8/g' \
| mysql -h FUTURE_HOST -u FUTURE_USER -p FUTURE_DB --default-character-set=utf8
# Flush the current database data on the future host
mysqldump -h CURRENT_HOST -u CURRENT_USER -p --no-create-db --no-create-info --skip-set-charset --default-character-set=latin1 CURRENT_DB \
| mysql -h FUTURE_HOST -u FUTURE_USER -p FUTURE_DB --default-character-set=utf8
Now i know what is the problem and the solution, But my question is how i can applied to my Django project-- Do i have to use my computer terminal and SSH session or is there any application of that?
this is a sceen shot of my DB in phpmyAdmin:
https://ibb.co/dDu7D5
Thank you
PS(I am using Django10 , Python3.5,Mysql,Webfaction sherd host)
Start with the "best practice" in Trouble with utf8 characters; what I see is not what I stored
Check for improper setup in Python: http://mysql.rjweb.org/doc.php/charcoll#python
Hopefully that 2-step mysqldump will work.
After loading, check some of the data by using "Test the data" in my first link. (SELECT HEX(col)...)
I'm getting this error when I run mysqldump like this:
$ mysqldump -u my_user -pXXX -h 127.0.0.1 --databases my_db > db_backup.sql
mysqldump: unknown variable 'sql-mode=STRICT_ALL_TABLES'
Does anyone know what could be going on?
I also get the same thing when I try to start the MySQL client.
Turns out I had "sql-mode=STRICT_ALL_TABLES" in the client settings section of my my.cnf file. I moved it to the server section and it seems all good.
It's a bad line in your .my.conf file, or maybe one of your system .ini files.
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.
I'm having some difficulty with mysqldump. I locked my tables and ran the following command:
mysqldump -u user -p password databasename using my actual password and database name.
When I run this from mysql I get a 1064 error that says there is an issue with my syntax. I've also tried running the command from terminal (outside of mysql) and receive a 'command not found' error message. I'm not entirely sure how I should be doing this (the explanations I've found so far have been vague).
Thanks for the help.
The mysqldump is a program, it cannot be executed from the mysql console. Run it from the shell.
Have a look at the syntax reference.
--user=user_name, -u user_name
--password[=password], -p[password]
As you see there is no space between -p and password. So, your command line should be like this:
>shell mysqldump -u <user_name> -p<user_password> ...
or
>shell mysqldump --user=<user_name> --password=<user_password> ...
You are missing the target backup file name:
# [mysql dir]/bin/mysqldump -u username -p password --databases databasename > /tmp/databasename.sql
MySQL Commands
the correct syntax is
mysqldump -u [username] -p[password] [databasename] > [backupfile.sql]
you should add the > backupfile.sql
the other error is believe your system doesn't recognize the mysqldump path and you should go directly to bin folder from mysql installation.
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.