Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i Setup utf-8 as standard character set for a mysql server?

do i have to recompile it?

i figured out diffent ways of setting the character set values see

http://dev.mysql.com/doc/refman/5.5/en/charset.html

but starting it with other values or my.cnf settings changed nothing. Because if i do:

sudo mysqld --verbose --help | grep charact

it always answers me latin1 as standard charset. the system is ubuntu lts server with a standard mysql install.

like image 773
dgAlien Avatar asked Jan 19 '11 13:01

dgAlien


People also ask

How do I set MySQL database to UTF-8?

To change the character set encoding to UTF-8 for the database itself, type the following command at the mysql> prompt. Replace dbname with the database name: Copy ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci; To exit the mysql program, type \q at the mysql> prompt.

How do I change the default character set in MySQL 8?

The MySQL server has a compiled-in default character set and collation. To change these defaults, use the --character-set-server and --collation-server options when you start the server.

Does MySQL support UTF-8?

MySQL supports multiple Unicode character sets: utf8mb4 : A UTF-8 encoding of the Unicode character set using one to four bytes per character. utf8mb3 : A UTF-8 encoding of the Unicode character set using one to three bytes per character.


2 Answers

Solution:

add this into my.cnf:

[mysqld]
character-set-server=utf8
character-sets-dir=/usr/share/mysql/charsets
default-character-set=utf8

[mysql]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

[mysqladmin]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

[mysqlcheck]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

[mysqldump]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

[mysqlimport]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

[mysqlshow]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8
#end
like image 71
dgAlien Avatar answered Sep 25 '22 17:09

dgAlien


[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
skip-character-set-client-handshake

[client]
default-character-set   = utf8

[mysql]
default-character-set   = utf8

UPDATE: Nowadays you should probably use utf8mb4.

like image 43
Quique Avatar answered Sep 24 '22 17:09

Quique