Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store non-english characters?

Tags:

mysql

Non-english characters are messed up in a text column. Arabic text looks like this:

نـجـم سـهـيـل

How to store non-english characters correctly?

like image 216
Yeti Avatar asked Jun 09 '10 18:06

Yeti


3 Answers

You should consider using utf8 to store your text.

You can do this at the database creation:

CREATE DATABASE mydb
  DEFAULT CHARACTER SET utf8
  DEFAULT COLLATE utf8_general_ci;

You can also configure mysql at installation or at startup to use utf8 (see Mysql manual)

The mysql manual pages cover all aspects of characterset and collations: http://dev.mysql.com/doc/refman/5.0/en/charset.html

The character set of the connection can be changed by

SET CHARACTER SET utf8

More details here and in the chapter Character set support

like image 101
marapet Avatar answered Oct 03 '22 04:10

marapet


What OS are you using?

If Linux then it's good to have a system locale set to utf8 also, like "en_US.utf8".

And, to be sure, issue an "SET NAMES UTF8" command to mysql just after connection.

(db character set/collation must also be utf8)

like image 44
zed_0xff Avatar answered Oct 03 '22 04:10

zed_0xff


The query below solved the issue.

ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
like image 27
Prateek Avatar answered Oct 03 '22 04:10

Prateek