I have this field
display_name varchar(30) latin1_swedish_ci
it takes English names as usual, but this database deals in different languages, and also users from all around enter there names, some of which are in different languages. french lets say, and a name stored in french is displayed like this ???????
what could be the reason? i believe it has something to do with this latin1_swedish_ci how can i make this field generic to take and display any name in any language correctly?
You need to call:
mysql_set_charset("utf8");
Also refer: 10.1.10 Unicode Support
Or the other way is to use utf-8 in MYSQL by adding this to your my.cnf:
collation_server = utf8_unicode_ci
character_set_server = utf8
and when you are executing your query the first use these two queries:
SET NAMES 'utf8';
CHARSET 'utf8';
if php code for connect to mysql,add code to (class mysql or code):
$dbLink = mysql_connect($argHost, $argUsername, $argPassword);
mysql_query("SET character_set_results=utf8", $dbLink);
and add code in meta tag to html code in head :
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
======================================================================
or
To set the default to UTF-8, you want to add the following to my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
Related
When i dump mysql data out , some data has changed because of the character_set_system which is UTF8.Server , client and connection character sete are utf8mb4.
I guess the problem is system character set and server character set differences.
I am trying to change system caharacter set from UTF8 to utf8mb4 with this
Change MySQL default character set to UTF-8 in my.cnf?
But i can not
The title is incorrectly phrased.
"utf8" is a "character set"
"utf8_bin" is a "collation" for the character set utf8.
You cannot change character_set... to collation. You may be able to set some of the collation_% entries to utf8_bin.
But none of that a valid solution for the problem you proceed to discuss.
Probably you can find more tips here: Trouble with UTF-8 characters; what I see is not what I stored
To help you further, we need to see the symptoms that got you started down this wrong path.
I have a weird problem with MySql supporting cyrilic alphabet. The database has been created in utf8_unicode_ci from the start, however the tables were not. Right now the table data, if supplied in cyrrilic looks like this ????????, if I create a table from start in utf there is no problem, however if I try to change the existing table encoding by using
ALTER TABLE <table_name> CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Which is supposed to change existing data or
ALTER TABLE Strategies
CHARACTER SET utf8,
COLLATE utf8_unicode_ci;
which is supposed to change future data, it doesn't work.
I have also change my.cnf file and added in
[mysqld]
#
#default-character-set=utf8 this one breaks mysql restart
character-set-server=utf8
skip-character-set-client-handshake
collation-server=utf8_unicode_ci
init-connect='SET NAMES utf8'
init_connect='SET collation_connection = utf8_general_ci'
If I run SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%'; I get:
I also change to utf directly in PHP my admin and it actually shows that the table is in utf but nothing happens to the existing ????????? or to the future cyrillic inputs.
Hopefully someone else had experinced this kind of issue, would be really greatfull for any help or suggestions. Thank you.
If a table starts out as latin1 and has latin1-encoded characters in it, use ALTER TABLE ... CONVERT TO CHARACTER SET utf8 (as you did)
Before converting, test the old encoding do two things:
SHOW CREATE TABLE ... -- to see that the columns say latin1
SELECT HEX(col) ... -- to see what the encoding looks like: é should show E9
I say, "before" because it is possible to cram utf8 into latin1 incorrectly. é should show C3A9 -- this is "double-encoding".
Do likewise after the conversion:
SHOW CREATE TABLE ... -- to see that the columns say utf8
SELECT HEX(col) ... -- to see what the encoding looks like; é should show C3A9
C383C2A9 would indicate double-encoding. A mess.
Do not depend on init-connect='SET NAMES utf8' if you connect as root, init-connect is ignored for root and any other SUPER user.
But... You say you put Cyrillic text into a latin1 column? That is "impossible" since latin1 cannot represent anything other than latin-based Western European characters. So... You probably have "double-encoding".
For more debugging, see Trouble with utf8 . Note especially "question mark".
To repair double-encoding, see Fixes , and pick the appropriate case. This link also says what you should have done (the 2-step Alter) instead of what you did.
I've some problems with special characters in PHP/MySQL (I don't know which one).
Then, I've data stored in a database,using php. I ensured before storing data to add this code:
header('Content-type:text/html; charset=utf-8');
$link=mysqli_connect("host","user","","db") or die(mysqli_error($link));
mysqli_query($link,"SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8';SET NAMES utf8");
I also ensured Apache uses the correct charset:
AddDefaultCharset utf-8
In addition I also tried to add on every html page the meta tag:
<meta http-equiv="content-type" content="text/html" charset="UTF-8">
Further, I saved all my php and html files in UTF-8 format.
I noticed that if I write a character like ò in a page and display that page it is correctly displayed. If I get a string query from a database containing ò, it doesn't display correctly, but if I change the code to:
header('Content-type:text/html; charset=iso-8859-1');
the query retrieved from the DB is correctly displayed, a normal writing not.
So,the problem is on mysql charset? How could it be if I setted it with the previous instructions?
try to change your column where you store this date to utf8 also
here some codes you may use.
Change the character-set/collation (database):
ALTER DATABASE db_name DEFAULT CHARACTER SET utf8;
Change the character-set/collation (table):
ALTER TABLE tbl_name DEFAULT CHARACTER SET utf8;
Change the character-set/collation (columns):
ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8;
Try using http://fi2.php.net/mysqli_set_charset function instead of the mysqli_query() you are using now.
I retrieve datas from mysql
This is normally which i have in db
This is normally i have in db
Seçimler, Şirketler ve Siyasi Partiler
it prints
Se�imler, ?irketler ve Siyasi Partiler
I use sql yog and change some preferences in my db
i set Charset to UTF8 and Collation is utf8_turkish_ci
but still retrieve datas like that
Se�imler, ?irketler ve Siyasi Partiler
why? What's the problem ?
this problem sounds like you've missed to specify a character encoding somewhere. to solve this, simply make sure you've set character encoding to utf-8 everywere (it doesn't actually need to be utf-8, just the same everywhere - but if you've messed up something and need to change some places anyway, i'd strongly recommend using utf-8):
tell MySQL to use utf-8. to do this, add this to your my.cnf:
collation_server = utf8_unicode_ci
character_set_server = utf8
before interacting with mysql, send this two querys:
SET NAMES 'utf8';
CHARSET 'utf8';
or, alternatively, let php do this afteropening the connection:
mysql_set_charset('utf8', $conn);
set UTF-8 as the default charset for your database
CREATE DATABASE `my_db` DEFAULT CHARACTER SET 'utf8';
do the same for tables:
CREATE TABLE `my_table` (
-- ...
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
assuming the client is a browser, serve your content as utf-8 and the the correct header:
header('Content-type: text/html; charset=utf-8');
to be really sure the browser understands, add a meta-tag:
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
and, last but not least, tell the browser to submit forms using utf-8
<form accept-charset="utf-8" ...>
You need to mention Charset to UTF8 in your selection query too.
SET NAMES 'utf8';
CHARSET 'utf8';
What made the difference for me was to add these lines:
collation_server = utf8_unicode_ci
character_set_server = utf8
to my.ini file (at the end of the document) I have tried everything else but they all failed until I made this change. It's really been a great help. Thanks oezi.
I added
$this->db->exec("SET NAMES 'utf8'");
in connection
and added
charset utf8 to my procedure parameters
Sample
PROCEDURE `up_users`(IN `lid` INT, IN `lfirstname` VARCHAR(100) CHARSET utf8, IN `llastname` VARCHAR(100) CHARSET utf8, IN `lstatus` VARCHAR(1) CHARSET utf8, IN `lpassword` VARCHAR(255) CHARSET utf8)
am using MySQL version 5.1.49 and I have not enabled UTF8 character encoding. The default character-set for MySQL is latin1. How can I change it show UTF8 characters?
Even when I query a table using Workbench I get 'NULL' in name section which I want, should display mutibyte characters.
ALTER DATABASE DEFAULT CHARACTER SET utf8
and for each table:
ALTER TABLE SomeTableName DEFAULT CHARACTER SET utf8
also if you will be viewing them from a webpage the HTML need this:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
and if you are using PHP, use htmlspecialchars() to display the values like this:
echo htmlspecialchars($row['some_field'], ENT_COMPAT, 'UTF-8');
and (again only for PHP) do this after mysql_connect():
mysql_query("SET NAMES 'utf8'");