mysql wrong connection encoding

2019-09-14 05:58发布

I have mysql tables with utf8 encoding. The Data Backend and phpmyadmin are also set to utf8.

But something went wrong and i was told the connection was set wrong. It is easy to fix, but the Problem is, that now the whole Database is in the wrong enconding and if i fix the connection, the wrong data will be displayed in the Backend. What would be the simplest way to "convert" all fields of all tables? I would have written a script that runs over all tables and fields with something like utf8_decode/encode, but I would like to know if there is a nicer way?

标签: mysql utf-8
1条回答
在下西门庆
2楼-- · 2019-09-14 06:42

If you have, for example, é instead of é in your DB, you could do the following

  • Export using mysqldump
  • Run a PHP script doing utf8_encode(file_get_contents('dump_file.sql')) and output it to a correctly encoded dump file
  • Import that new file using mysql

I guess that there could be smarter ways but I hope this will help.

查看更多
登录 后发表回答