Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert output of MySQL query to utf8

Tags:

sql

mysql

utf-8

I have a table in my database and I want run a query like

SELECT column1, column2 FROM my_table WHERE my_condition; 

but I want the mysql to return the column2 in utf8 encoding. Is it any function in mysql to do such task? What is that?

like image 306
orezvani Avatar asked Apr 17 '13 04:04

orezvani


People also ask

How convert MySQL database from latin1 to UTF-8?

Similarly, here's the command to change character set of MySQL table from latin1 to UTF8. Replace table_name with your database table name. mysql> ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci; Hopefully, the above tutorial will help you change database character set to utf8mb4 (UTF-8).

How do I change utf8mb4 to UTF-8?

To solve the problem open the exported SQL file, search and replace the utf8mb4 with utf8 , after that search and replace the utf8mb4_unicode_520_ci with utf8_general_ci . Save the file and import it into your database. After that, change the wp-config. php charset option to utf8 , and the magic starts.


1 Answers

You can use CAST and CONVERT to switch between different types of encodings. See: http://dev.mysql.com/doc/refman/5.0/en/charset-convert.html

SELECT column1, CONVERT(column2 USING utf8) FROM my_table  WHERE my_condition; 
like image 51
josh-fuggle Avatar answered Oct 01 '22 12:10

josh-fuggle