Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change all the tables in my database to UTF8 character set?

My database is not in UTF8, and I'd like to convert all the tables to UTF8, how can I do this?

like image 352
nubela Avatar asked Jan 27 '10 21:01

nubela


People also ask

How do I change the character set of all tables in MySQL?

Replace database_name and table_name below with database and field names respectively. alter table database_name. table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; If you want to change collation of all tables in your database, you need to run the above query for each table separately.

How do I convert MySQL database to UTF-8 encoding?

To change the character set encoding to UTF-8 for the database itself, type the following command at the mysql> prompt. Replace dbname with the database name: Copy ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci; To exit the mysql program, type \q at the mysql> prompt.

How do I modify all tables in a database?

To easily convert all tables in one database, use the following: SET @DB_NAME = DATABASE(); SELECT CONCAT('ALTER TABLE `', table_name, '` ENGINE=InnoDB;') AS sql_statements FROM information_schema. tables WHERE table_schema = @DB_NAME AND `ENGINE` = 'MyISAM' AND `TABLE_TYPE` = 'BASE TABLE';


1 Answers

For single table you can do something like this:

ALTER TABLE tab CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci; 

For the whole database I don't know other method than similar to this:

http://www.commandlinefu.com/commands/view/1575/convert-all-mysql-tables-and-fields-to-utf8

like image 111
Tomasz Zieliński Avatar answered Sep 25 '22 17:09

Tomasz Zieliński