I have a Spring web application talking to a mySQL database through hibernate. I am trying to set up utf8mb4 as the database character encoding. I have performed the following steps:
Setup my database using
SET NAMES utf8mb4;
ALTER DATABASE mydb CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
Change hibernate url to
hibernate.connection.url = jdbc:mysql://localhost:myport/mydb?character_set_server=utf8mb4
Add SET NAMES 'utf8mb4' to database connection initial SQLs on my Spring application configuration
Added character_set_server=utf8mb4 at my.cnf
I managed to get my application working properly with a local database. Also what I found is that step 2 is not necessary and without step 4 my setup was not working locally.
In Openshift however I have not found a way to perform step 4. Is there any other solution to this problem? I have tried to change character_set_server through phpMyAdmin variables but this is not working either.
There's another MySQL cartridge which can be configured to use utf8mb4. Just backup the data from your database. Remove your MySQL cartridge and add this one:
https://github.com/amgohan/openshift-origin-cartridge-mysql-utf8mb4
And finally restore the backup into your new database.
Related
When we want to store a string with emojis to our MySQL database, we get this error:
Conversion from collation utf8_general_ci into utf8mb4_unicode_520_ci impossible for parameter
Can someone explain to me why Node is sending it as utf8 to MySQL and how I can declare that we have an utf8mb4 collation? I tried several different encodings on the database side, but I think it is a Node.js or driver configuration that is missing.
The backend is based on Express.js, running on a Debian system within an lts-alpine docker container and the request is sent by a React Native app.
Thx, Florian
I want to move my MySQL database to an older version server (5.7 to 5.1).
I get errors because it is created using utf8mb4 .
If i manually change utf8mb4 to utf8 the data become unreadable because of multilinguality.
I have access only to phpMyAdmin in both servers so I can't use mysqldump.
Any ideas?
It seems I've figured out a solution.
Use at export mysql40 compatibility mode, replace utf8mb4 with utf8 and change the character set of tables from phpmyadmin to utf8_unicode_ci.
Hope this will save some time from a fellow in future.
I have ejabberd 16.01 that works well with MySQL, the problem is that it store only the regular emoji not the 4-bytes emoji. If I use a terminal, connect to the database, set the charset to utf8mb4 and run insert query, I can insert all type of icons, so the db is configured in the right way!
So i ejabberd put a message in offline storage all icons of 4-Bytes become "?????????" is there a way to set the charset to utf8mb4 for ejabberd mod offline?
How can I fix it? Do you have any ideas?
Thanks!
You need two things:
Ensure you have ejabberd 16.02 or newer that forces UTF8MB4 as default for emoji retrieval (Insertion is already in UTF8MB4 since years, if the table is correctly defined)
Ensure your MySQL schema has been properly created with UTFMB4 support.
Last week I migrated my db in another platform. I did a mysqldump export from phpmyadmin panel and then I imported it in a new platform using the bigdump script.
The sql dump file that I have imported was originally stored in a db that was setting in this manner:
MySQL charset: UTF-8 Unicode (utf8)
MySQL connection collation: utf8_unicode_ci
I exported the db choosing utf8 character set but if I look inside the mysqldump file for every table appears:
DEFAULT CHARSET=latin1
Now I have a problem with the accented letter (like à, è, ò, ì) that are displayed like ò , Ã...etc.
For manage my new db I use MySQL Workbench and if i prompt:
show variables like 'char%';
I see that all the values are set in utf8.
How can I solve the problem? I'm not a Mysql and db expert!
You can try changing the current character set of a table to the original:
alter table TABLE_NAME convert to character set utf8 collate utf8_unicode_ci;
Your tables seem to use latin1, despite the utf8 settings you mentioned. So you have several options here:
Take the created dump as is and send it to the server using the latin1 connection charset (not utf8). This will however create the tables with latin1 charset as they are on the source server.
Convert the dump to utf-8 if you have a tool that can do it. You have to change the charset settings for your tables in the script too, though.
Convert your tables to utf8 and do the dump again.
Combine 1 + 3, but convert your target tables instead. Useful if you cannot change the source tables.
Have you actually tried MySQL Workbench to restore the dump to your new server? I'm quite sure it should be able to handle this case with a latin1 encoded backup. See Server Administration section -> Data Import/Restore.
I've uploaded some data to a MySQL (5.5.15 for osx10.6) database using UTF8 encoding, though for some reason I had to specify its encoding as latin1 when I LOADed it.
I reckon this part is good because when I write to an OUTFILE, my unicode 'nu' characters come out OK in a terminal and in Vim.
However, when I look at them within a MySQL session, and when I try to edit the fields from Django admin, I get mangled characters (latin1?).
So, my question is: how to I tell a MySQL client and (especially) Django to read my database as UTF-8, the way it oughta?
At the command line, I tried
--default_character_set=utf8
and also
'SET NAMES UTF8;'
at the MySQL prompt, but they do not work.
When I look at VARIABLES LIKE 'char%', they're all set to utf8 apart from character_set_server which is latin1. If I set it to utf8.... that doesn't work either.
I'd be grateful if someone could give me some pointers here, especially about how to configure Django to talk to my database properly.
Thanks!
Add in your .cnf:
[mysqld]
character-set-server = utf8
collation-server = utf8_general_ci
skip-character-set-client-handshake