steps to convert single databse to utf8mb4 in mysql - mysql

i want to change the character set of a table in mysql database to utf8mb4 without changing in config file .i dont want entire database to use utf8mb4 .
i already changed the database,table and procedures character set and collation to utf8mb4
alter database DBNAME CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
alter table tblname CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
i want to store emojis in mysql databse without changing the entire database to utf8mb4 .please help me

Related

Problem changing mysql database encoding to utf8mb4 in Gcloud

I have a mysql database in Gcloud using utf8 enconding and I want to change it to utf8mb4 to support storing emoticons.
I did this using my local version of mysql in my laptop and it worked fine using:
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER DATABASE db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
But when I try to do the same in Gcloud, the commands are accepted and the encoding changes but I keep receiving this error when trying to insert the record:
"error": "could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement: Incorrect string value: '\xF0\x9F\xA6\x95' for column 'text' at row 1" }
I also changed character_set_server variable in gcloud to utf8mb4 and restarted the engine but it does not work. Does anybody know what else should I change?
Thanks!

Not all character sets and collation sets change to utf8mb4(.unicode.ci)

I am trying to set character sets to utf8mb4 and collation sets to utf8mb4_unicode_ci. On my website the emoji's looks fine when I get the data out of the table with php/mysql select. Only in phpMyAdmin (4.8.4) I see most emoji's as one questionamrk.
I try this:
Add to /etc/my.cnf:
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
Restart systemctl restart mariadb
I use on my website mysqli_set_charset($con, "utf8mb4");, <form accept-charset="UTF-8"> and <meta charset="utf-8">.
Result of SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%':
What am I doing wrong?
I use mysql version 5.5.60 (Mariadb).
Edit:
The problem might be phpmyadmin (4.8.4). It seems that phpMyAdmin is still using utf8. The global variabelen are set to utf8mb4 or utf8mb4_unicode_ci but I can't change the session variabelen:
I set in config.inc.php:
In the 'normal' table in phpMyAdmin:
And when I try SET NAMES everything looks fine:
Under General settings in phpMyAdmin the server connection collation is set on utf8_unicode_ci. I can select utf8mb4_unicode_ci, but then it switches back to utf8_unicode_ci :(
And on my website with select everything looks oké:

How to change the connection collation of Mysql

How can I change connection collation of mysql database?
I am using Mysql workbench 5.5 and mysql 5.5 in ubuntu 14.
When I execute a stored procedure, an error occurs:
Error Code: 1267. Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '='
I have search though the internet, which has a temp solution that is to amend
COLLATE utf8_unicode_ci;
in the stored procedure.
But I want to fix this problem for all stored procedures in the future. I have found
SHOW VARIABLES LIKE 'collation%';
which return this.
collation_connection utf8_general_ci
collation_database utf8_unicode_ci
collation_server latin1_swedish_ci
how can I change utf8_general_ci to utf8_unicode_ci?
Look into your my.cnf, find the contents below near collation_server:
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
Then change your collation variables to:
collation_connection utf8_unicode_ci
collation_server latin1_swedish_ci
Remember to restart MySQL server service.
For DB collation, you can use the following SQL:
ALTER DATABASE <database_name> CHARACTER SET utf8 COLLATE utf8_unicode_ci;
or you can do it at Alter database screen in MySQL Workbench (always update this to the latest version!)
Firstly, I think the error message is because of the collation of stored procedure (connection) doesn't match the table. But I was wrong, the reason for the error is because of the collation of the column doesn't match the collation of the table.
I want to change to collation of column to 'utf8_unicode_ci' in my case. So
I have run this statement:
alter table <YourTableName>
MODIFY <YourColumnName> VARCHAR(XXX) COLLATE 'utf8_unicode_ci';
Please be aware that change of collation may result in data loss. For me, General -> Unicode, with all English in varchar column. There is none.
Further reading:
http://dev.mysql.com/doc/refman/5.7/en/charset-column.html
http://dev.mysql.com/doc/refman/5.7/en/charset-connection.html
http://dev.mysql.com/doc/refman/5.7/en/charset-database.html

In MySQL, what do I put inside my.cnf so that all tables are UTF-8 that works with emojis by default?

I'd like every table and database (to be created) to be utf-8 that works with emojis. I understand that there are a few variables I need to define inside my.cnf:
init_connect='SET collation_connection = ??? '
init_connect='SET NAMES ???'
character-set-server = ???
collation-server = ???
However, I'm not sure what to put in the ???. What do I put inside my.cnf?
This article may help: https://mathiasbynens.be/notes/mysql-utf8mb4#utf8-to-utf8mb4
It explains in detail how to switch to utf8mb4 to support full unicode, thus allowing emojis using the following config:
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
In addition to changing to utf8mb4 as #eol suggests, there may be more to do.
If you already have tables that have utf8 columns; do ALTER TABLE .. CONVERT TO CHARACTER SET utf8mb4.
When you connect, be sure to establish UTF-8 if the client has a non-mysql way of doing it, or use SET NAMES utf8mb4.
Keep in mind that root ignores init-connect. You should have a non-root 'user' for the application.
To support full Unicode in MySQL databases
For database: ALTER DATABASE DATABASE_NAME CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
For table:
ALTER TABLE TABLE_NAME CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
For column: ALTER TABLE TABLE_NAME CHANGE COLUMN_NAME COLUMN_NAME VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

MySQL: Set Default Collation Connection and MySQL Dump

I am running MySQL 5.5.20 on Windows Vista Business. I am having a bit of a problem with collation_connection. My default charset is utf8 and collation is ut8_unicode_ci. However, when I perform mysql dumps on the database, my functions and procedures have the collation_connection showing utf8_general_ci; for example,
/*!50003 SET collation_connection = utf8_general_ci*/ ;
Is it possible to specify MySQL to default to ut8_unicode_ci for collation_connection? I use MySQL Workbench to perform the mysql dumps.
Nowadays consider using utf8mb4 instead of utf8.
If you want the behavior you're describing, you first would execute:
SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;
Then redefine affected functions, procedures and triggers.
Next time you execute mysqldump, generated file will have lines like this:
/*!50003 SET collation_connection = utf8mb4_unicode_ci*/ ;
More details about SET NAMES in MySQL Reference Manual.