0

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:

  1. Setup my database using

    SET NAMES utf8mb4; 
    ALTER DATABASE mydb CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
    
  2. Change hibernate url to

     hibernate.connection.url = jdbc:mysql://localhost:myport/mydb?character_set_server=utf8mb4
    
  3. Add SET NAMES 'utf8mb4' to database connection initial SQLs on my Spring application configuration
  4. 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.

Kurt Van den Branden
  • 11,995
  • 10
  • 76
  • 85
plato
  • 44
  • 3
  • Look for Spring and Hibernate in http://mysql.rjweb.org/doc.php/charcoll#other_computer_languages – Rick James Nov 16 '16 at 00:53
  • Thanks for the link but I have not managed to find any solution to my problem regarding utf8mb4 – plato Nov 19 '16 at 23:28
  • What symptoms do you have? See http://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored for several common problems, plus solutions. – Rick James Nov 19 '16 at 23:45
  • Well my problem is that on mySQL database on Openshift cloud all emojis are stored as ??. The issue is that character_set_server is set to latin rather than utf8mb4. I know that in order to fix this I need to modify my.cnf but this is not possible on the Openshift cloud. So I am looking for any other solution that I can use on Openshift – plato Nov 21 '16 at 10:44
  • Search for "question marks" in [_this_](http://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored) Q&A. – Rick James Nov 21 '16 at 16:46
  • Thanks for this link. I read the section for the question marks but I did not find any solution I could use in my case – plato Nov 21 '16 at 20:24

1 Answers1

0

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.

kostas
  • 51
  • 8