My database is not in UTF8, and I'd like to convert all the tables to UTF8, how can I do this?
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.
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.
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';
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With