How to change MYSQL Database columns filed Collation - mysql

I need to change below collation to utf8_general_ci

You can use Alter table clause
ALTER TABLE `change_messages` CHANGE `message` `message` TEXT CHARSET utf8 COLLATE utf8_general_ci;

Related

change all existing collation of columns

I have a table which some of its columns has collation of utf8_bin. But I need to change them to utf8_unicode_ci.
I know this query for do it:
ALTER TABLE `shn_sho_cities` CHANGE `city_name` `city_name` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ;
but as I want change all columns which have utf8_bin instead of writing a query for each column.
Is there any way which I could do this?
The following code will generate the required queries to change your collations, to utf8mb4 with utf8mb4_unicode_ci
SELECT CONCAT('ALTER TABLE `', TABLE_NAME,'` CONVERT TO CHARACTER SET
utf8mb4 COLLATE utf8mb4_unicode_ci;') AS mySQL
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA= "YOU-DB-NAME"
AND TABLE_TYPE="BASE TABLE"

Can column comment be a utf-8 in MySQL?

Here is quetions about adding comment to column for MySQL. Can this comment be utf-8? Also what encoding MySQL uses for these columns by default?
Default character set and collation is set when the database is created
CREATE DATABASE mydb
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
You can modify character set on a specific column like this
ALTER TABLE t MODIFY col1 CHAR(50) CHARACTER SET utf8;

Creating a MySQL Database with a Specific Character Set and Collation

When creating a MySQL database with CREATE SCHEMA, it uses MySQL's default character set and collation. But I want to change that.
How do I create a MySQL Database with a specific character set and collation?
You can try like this:
CREATE DATABASE IF NOT EXISTS someDatabase
DEFAULT CHARACTER SET = 'utf8' DEFAULT COLLATE 'utf8_general_ci'
and if the database is already created, then you can alter is like this:
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE SCHEMA `my_database`
DEFAULT CHARACTER SET utf8
COLLATE utf8_unicode_ci ;

Mysql -change DB,tables to utf8

In /etc/my.cnf the following has been added
character-set-server=utf8
collation-server=utf8_general_ci
But for the database and tables created before adding the above how to convert the database and tables to utf8 with collation settings
Well, the database character set and table character set are just defaults (they don't affect anything directly). You'd need to modify each column to the proper charset. PHPMyAdmin will do this for you (just edit the column, then change the character set). If you want to do raw SQL, you'll need to know the column definition (SHOW CREATE TABLE foo will show you the definition). Then, you can use ALTER TABLE to change the definition.
To change the default charset for a table:
ALTER TABLE `tablename` DEFAULT CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
To change the charset of a column with the definition `foo VARCHAR(128) CHARACTER SET 'foo' COLLATE 'foo'``:
ALTER TABLE `tablename` MODIFY
`foo` VARCHAR(128) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
https://serverfault.com/questions/65043/alter-charset-and-collation-in-all-columns-in-all-tables-in-mysql
And:
http://www.mysqlperformanceblog.com/2009/03/17/converting-character-sets/

Mysql column to utf8_bin

I have a table in mysql. I want to change one of the columns to have utf8_bin as it's collate attribute.
I know the command to do for whole table is like:
ALTER TABLE temp CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
But how do I do it for individual columns?
Thanks for the help
It's right in the manual
Their example
ALTER TABLE t1 MODIFY
col1 VARCHAR(5)
CHARACTER SET latin1
COLLATE latin1_swedish_ci;