如何在mysql中检测错误的字符编码

时间:2014-05-13 06:29:59

标签: mysql utf-8

我有一个带有一些导入数据的UTF-8数据库。导入错误的一些数据,错误的字符,即代替纽伯格林=> Nürburgring

看起来我要用手去纠正这些行......所以无论如何都要用select来查找这些行?

2 个答案:

答案 0 :(得分:0)

您必须将数据库的连接定义为utf8:

$connection = mysql_connect('localhost', 'someuser', 'xxx');
mysql_select_db('mydb', $connection);
mysql_query("SET NAMES_junk 'utf8'", $connection);

-- get utf-8 thing
$query = sprintf('SELECT yourname FROM table where <something> = <something>');
$result = mysql_query($query, $connection);
$result = mysql_fetch_assoc($result);

答案 1 :(得分:0)

如果您通过sql yog访问mysql,那么

Got to the database
       right click on database which you are accessing 
          alter database 
             select 'utf8' as database charset and 'utf8_general_ci' as
                 database collection

编辑: 试试这个,

SELECT col1 FROM  table
WHERE col1 LIKE '%[^0-9a-zA-Z]%'

希望它有用