Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm having problems when configuring a server with UTF8. Well, I'm not configuring it exactly. I client from where I work does and I think that he's not an expert configuring web servers.

My PHP+MySQL application needs to use Apache and MySQL in UTF8. After various e-mails, this person configured apache with utf8 support but now it's time to MySQL and there is no way we can configure it. I don't know what to do because I'm not a system administrator but I configured apache/mysql on ubuntu with utf8 support looking into Google.

What I said to him is that please, use the next configuration on my.cnf:

[mysqld]
character-set-filesystem=UTF8
character-set-server=UTF8
default-collation=UTF8_general_ci
default-character-set=UTF8

[client]
default-character-set=UTF8

[mysqldump]
default-character-set=UTF8

But nothing changed. He passed me the my.cnf that is running, you can see it here: http://pastebin.com/NfcgKKiM ... and doesn't works the UTF8 encoding on MySQL.

What I did in PHP is launch a MySQL query every time with SET NAMESutf8`` and it works as UTF8 but I don't think that is the best option but proves that something is miss configured. No?

What I can do? What I can say to the server admin?

Thank you and sorry for my bad English!

share|improve this question

3 Answers 3

up vote 0 down vote accepted

What "CHARACTER SET" and "COLLATE" in DB(show create database DB_NAME)?

Try:

[mysqld]
init-connect='SET NAMES utf8'
share|improve this answer

You're missing a couple more parameters in your my.cnf, here's what it looks like in mine

[client] 
default-character-set=utf8 

[mysql] 
default-character-set=utf8 

[mysqld]
init_connect='SET collation_connection = utf8_general_ci'
init_connect='SET NAMES utf8'
default_character_set=utf8
character_set_server = utf8
collation_server = utf8_general_ci

This should give you full UTF8 support on the MySQL backend

share|improve this answer
  • Make sure your tables have the correct character set in MySQL
  • Use UTF-8 content encoding on all pages
  • Set your MySQL session character set to UTF-8

All my pages begin like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

My MySQL connection looks like this: (note the PDO::exec() call)

try {
  $dbh = new PDO(('mysql:host=' . $mbdbhost . ';dbname=' . $mbdbname), $mbdbuser, $mbdbpass, array(PDO::ATTR_PERSISTENT => true));
  $dbh->exec('SET CHARACTER SET utf8');
} catch (PDOException $e) {
  header("Location: error.php");
}

My tables look a bit like this:

CREATE TABLE IF NOT EXISTS fotouser (
  idfotouser INT NOT NULL AUTO_INCREMENT ,
  person INT NOT NULL ,
  PRIMARY KEY (idfotouser) ,
  INDEX person (person ASC) ,
  CONSTRAINT person
   FOREIGN KEY (person)
   REFERENCES mb_person (idmb_person)
 ON DELETE NO ACTION
 ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_swedish_ci ;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.