My system runs on Linux Mandriva, RDBMS - MySQL 5.
I need to have the database and tables created in UTF-8.
Here is a fragment of hibernate.cfg.xml -
...
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
...
my.cnf -
# The MySQL server
[mysqld]
...
default-character-set=cp1251
character-set-server=cp1251
collation-server=cp1251_general_ci
init-connect="SET NAMES cp1251"
skip-character-set-client-handshake
...
[mysqldump]
...
default-character-set=cp1251
...
Some class, for example -
@Entity
@Table(name = "USER")
public class User {
@Id
@Column(name = "USERID")
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@Column(name = "USERNAME")
private String name;
@Column(name = "USERPASSWORD")
private String password;
@Column(name = "USERIP")
private String ip;
// getter's and setter's here
...
But when the tables are generated, I see the encoding latin1
For example-
SHOW CREATE TABLE USER;
USER | CREATE TABLE `user` (
`USERID` int(11) NOT NULL auto_increment,
`USERIP` varchar(255) default NULL,
`USERNAME` varchar(255) default NULL,
`USERPASSWORD` varchar(255) default NULL,
PRIMARY KEY (`USERID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
How to change the encoding to UTF-8?
I would be most grateful for the information!
Thank you!
...
This is strange, I have changed all to utf8 -
# The MySQL server
[mysqld]
...
default-character-set=utf8
character-set-server=utf8
collation-server=utf8_general_ci
init-connect="SET NAMES utf8"
skip-character-set-client-handshake
...
[mysqldump]
...
default-character-set=utf8
...
And now -
SHOW CREATE TABLE USER;
USER | CREATE TABLE `USER` (
`USERID` int(11) NOT NULL auto_increment,
`USERIP` varchar(255) default NULL,
`USERNAME` varchar(255) default NULL,
`USERPASSWORD` varchar(255) default NULL,
PRIMARY KEY (`USERID`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251 |
See Question&Answers more detail:
os