i am running backups of my mysql database with this command:
mysqldump -u admin -p`cat /etc/psa/.psa.shadow` --hex-blob --skip-opt --single-transaction --add-drop-table --create-options --quick --extended-insert --max_allowed_packet=32M --default-character-set=utf8 --disable-keys databasename -r database.sql
In an inconsistent way this dump produces in some cases things like that:
Screenshot of the dumpfile in texteditor
or copied via clipboard:
21-3′,1,’2𩐂 𩐂 珂 p参 XªP ªP @ ªP 1 08:42:08′),(1
the problem is that if I want to restore the file it creates errors.
It is inconsistent as it happens in every database field independently of its datatype or encoding.
does anybody has an idea why this happens?
thanks for your help
I have searched a lot and added for example –hex-blob to the dump statement, but it did not help to dump the contents correctly in utf8.
2
Answers
first of all many thanks for your answer. I followed all steps and changed all tables with a little script to the values you indicated. Anyway even if I change it manually in MySQL Workbench it shows utf8mb4_0900_ai_ci as Collation. is this correct?
But finally the result is still the same. It produces these strange binary blobs and running the restore script in order to import it in my local mysql server it gives this result:
ERROR at line 48: ASCII ' ' appeared in the statement, but this is not allowed unless option --binary-mode is enabled and mysql is run in non-interactive mode. Set --binary-mode to 1 if ASCII ' ' is expected.
Do you have any other tipp to solve this?
Greetings
To resolve the issue with inconsistent encoding in your
mysqldump
, follow these steps precisely:1. Use
--default-character-set=utf8mb4
in Your CommandUpdate your
mysqldump
command to explicitly set the character set toutf8mb4
, ensuring compatibility with all Unicode characters. Use the following updated command:2. Check the Database and Table Encoding
Run the following SQL queries to verify that your database and tables use the correct encoding:
utf8mb4
.3. Increase
max_allowed_packet
Ensure both the MySQL server and client have sufficient packet size to handle large data. Edit the
my.cnf
file:Restart MySQL:
4. Validate and Restore
Once the dump file is created, validate it before restoring:
5. Verify Data Integrity
After restoration, verify the restored data matches the source:
Why This Works
--default-character-set=utf8mb4
: Ensures consistent handling of Unicode data during the dump process.max_allowed_packet
: Prevents data truncation for large rows.Let me know if you encounter any issues during these steps!