MYSQL - Turkish character - mysql

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)

Related

How can i change Mysql character_set_system UTF8 to utf8bin

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.

Problems with charset in PHP/MySQL

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.

Incorrect string value: '\xF0\x9F\x8E\xB6\xF0\x9F...' MySQL

I am trying to store a tweet in my MYSQL table. The tweet is:
quiero que me escuches, no te burles no te rias, anoche tuve un sueño que te fuiste de mi vida 🎶🎶
The final two characters are both 'MULTIPLE MUSICAL NOTES' (U+1F3B6), for which the UTF-8 encoding is 0xf09f8eb6.
The tweet_text field in my table is encoded in utf8mb4. But when I try to store the tweet in that column I get the following error message:
Incorrect string value: '\xF0\x9F\x8E\xB6\xF0\x9F...' for column 'tweet_text' at row 1.
What is going wrong? How can I fix this? I need to store multiple languages as well and this character set works for all languages but not for the special characters like emoticons and emojis.
This is my create table statement:
CREATE TABLE `twitter_status_data` (
`unique_status_id` bigint(20) NOT NULL AUTO_INCREMENT,
`metadata_result_type` text CHARACTER SET utf8,
`created_at` text CHARACTER SET utf8 NOT NULL COMMENT 'UTC time when this Tweet was created.',
`id` bigint(20) unsigned NOT NULL COMMENT 'Unique tweet identifier',
`id_str` text CHARACTER SET utf8 NOT NULL,
`tweet_text` text COMMENT 'Actual UTF-8 text',
`user_id_str` text CHARACTER SET utf8,
`user_name` text COMMENT 'User''s name',
`user_screen_name` text COMMENT 'Twitter handle',
`coordinates` text CHARACTER SET utf8,
PRIMARY KEY (`unique_status_id`),
KEY `user_id_index` (`user_id`),
FULLTEXT KEY `tweet_text_index` (`tweet_text`)
) ENGINE=InnoDB AUTO_INCREMENT=82451 DEFAULT CHARSET=utf8mb4;
I was finally able to figure out the issue.
I had to change some settings in mysql configuration my.ini
This article helped a lot
http://mathiasbynens.be/notes/mysql-utf8mb4#character-sets
First i changed the character set in my.ini to utf8mb4
Next i ran the following commands in mysql client
SET NAMES utf8mb4;
ALTER DATABASE dreams_twitter CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
Use the following command to check that the changes are made
SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
I had hit the same problem and learnt the following-
Even though database has a default character set of utf-8, it's possible for database columns to have a different character set in MySQL.
Modified dB and the problematic column to UTF-8:
mysql> ALTER DATABASE MyDB CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'
mysql> ALTER TABLE database.table MODIFY COLUMN column_name VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
Now creating new tables with:
> CREATE TABLE My_Table_Name (
twitter_id_str VARCHAR(255) NOT NULL UNIQUE,
twitter_screen_name VARCHAR(512) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
.....
) CHARACTER SET utf8 COLLATE utf8_unicode_ci;
It may be obvious, but it still was surprising to me, that SET NAMES utf8 is not compatible with utf8mb4 encoding. So for some apps changing table/column encoding was not enough. I had to change encoding in app configuration.
Redmine (ruby, ROR)
In config/database.yml:
production:
adapter: mysql2
database: redmine
host: localhost
username: redmine
password: passowrd
encoding: utf8mb4
Custom Yii application (PHP)
In config/db.php:
return [
'class' => yii\db\Connection::class,
'dsn' => 'mysql:host=localhost;dbname=yii',
'username' => 'yii',
'password' => 'password',
'charset' => 'utf8mb4',
],
If you have utf8mb4 as a column/table encoding and still getting errors like this, make sure that you have configured correct charset for DB connection in your application.
Change database charset and collation
ALTER DATABASE
database_name
CHARACTER SET = utf8mb4
COLLATE = utf8mb4_unicode_ci;
change specific table's charset and collation
ALTER TABLE
table_name
CONVERT TO CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
change connection charset in mysql driver
before
charset=utf8&parseTime=True&loc=Local
after
charset=utf8mb4&collation=utf8mb4_unicode_ci&parseTime=True&loc=Local
From this article https://hackernoon.com/today-i-learned-storing-emoji-to-mysql-with-golang-204a093454b7
According to the create table statement, the default charset of the table is already utf8mb4. It seems that you have a wrong connection charset.
In Java, set the datasource url like this:
jdbc:mysql://127.0.0.1:3306/testdb?useUnicode=true&characterEncoding=utf-8`.
?useUnicode=true&characterEncoding=utf-8 is necessary for using utf8mb4.
It works for my application.
FOR SQLALCHEMY AND PYTHON
The encoding used for Unicode has traditionally been 'utf8'. However, for MySQL versions 5.5.3 on forward, a new MySQL-specific encoding 'utf8mb4' has been introduced, and as of MySQL 8.0 a warning is emitted by the server if plain utf8 is specified within any server-side directives, replaced with utf8mb3. The rationale for this new encoding is due to the fact that MySQL’s legacy utf-8 encoding only supports codepoints up to three bytes instead of four. Therefore, when communicating with a MySQL database that includes codepoints more than three bytes in size, this new charset is preferred, if supported by both the database as well as the client DBAPI, as in:
e = create_engine(
"mysql+pymysql://scott:tiger#localhost/test?charset=utf8mb4")
All modern DBAPIs should support the utf8mb4 charset.
enter link description here
I had use an emoji in my string that was the reason for this error.
So make sure you are not using some incorrect string that is not valid to save into the database.
As others said, it's because you are trying to save a 4 bytes of data into less space.
If you are facing the similar issue in java and don't have the flexibility to change the charset and collate encoding of database than this answer is for you.
you can use the Emoji Java library to achieve the same. You can convert into alias before saving/updating into database and convert back to unicode post save/update/load from database. The main benefit is readability of the text even after the encoding because this library only alias the emoji's rather than whole string.
I changed MySQL settings and still the same. Finally I used the function utf8_decode() on the string before insert.

How to configure mysql version '5.1.49-1ubuntu8' to show multibyte charecters?

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'");

How to retrieve special Char from database?

I am trying to retrieve a special Greek character µ from a MySQL database but in HTML it is
showing this �.
My HTML charset: content="text/html; charset=windows-1252"
In addition, after it retrieves the character it also need to be able to use the character to compare back in the database.
I've tried putting the HTML code in the database like μ then it is not able to compare back to the database because HTML turns it into µ.
How can I do this appropriately?
First, I would recommend using utf8 as your charset.
Start by switching the default for the database:
ALTER DATABASE db_name CHARACTER SET utf8;
Next, to switch your tables over to utf8 apply this SQL:
ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8;
which you will have to do for each table.
Finally, and quite unfortunately, you have to know convert all the character data columns that were made under the old charset (varchar, text, etc.). You have to do this by way of first casting to a BLOB so that the characters already stored are not mangled:
alter table tbl_name change col_name col_name LONGBLOB;
alter table tbl_name change col_name col_name LONGTEXT CHARACTER SET utf8;
Wordpress publishes a column type by column type guide on how to do this step: converting database charset columns.
Then, finally update the charset declaration in your xhtml (or without the ending / if it is html):
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
This process is arduous, but will convert the database. It is much easier to start a db in utf8.
This is all assuming MySQL 5, for which you can see the Mysql 5 ALTER TABLE reference.
Try this on your table containing the special chars (based off of this post):
ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8;
See Shelhamer's answer, but you also need to set the db connection to utf8. You can either use mysql_set_charset('utf8'); right after you connect to the DB. Alternatively run the following query after your're connected:
SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8';
however, i would still recommend you use htmlentities() when displaying your content on a website to make sure is's all valid HTML. Firefox tends to barf if you mix up the encoding.
in php use utf8_encode() before saving it to the database.
It will solve the problem