在我的wordpress网站中,数据库(mysql)已升级,以前的表字符集为utf8mb4,但现在变成了utf8,它将不支持utf8mb4。
因此,在我的wp-config文件中,我将字符集更改为utf8。

但是我收到这样的错误

HTTP错误500

最佳答案

请使用代码转换您的WordPress数据库。



<?php
error_reporting(E_ALL);
$dbname = "YOUR-DATABASE-NAME";
mysql_connect("localhost", "YOUR-DATABASE-USERNAME", "YOUR-DATABASE-PASSWORD") or die(mysql_error());
mysql_select_db("$dbname");
mysql_query("SET NAMES 'utf8';") or die(mysql_error());

$query = "SHOW TABLES";
$result = mysql_query($query) or die(mysql_error());
while ($data = mysql_fetch_assoc($result)) {

	$table = $data["Tables_in_$dbname"];
	$query = "alter table $table convert to character set utf8 collate utf8_turkish_ci";
	mysql_query($query) or die(mysql_error());
	echo "<b>$table</b><br>";

	$query = "SHOW COLUMNS FROM $table";
	$result_2 = mysql_query($query) or die(mysql_error());
	while ($columns = mysql_fetch_assoc($result_2)) {

		if (
				(stripos($columns['Type'], 'varchar')!==false)
				||
				(stripos($columns['Type'], 'text')!==false)
		) {
			$query = "ALTER TABLE $table MODIFY {$columns['Field']} {$columns['Type']} CHARACTER SET utf8 COLLATE utf8_turkish_ci";
			mysql_query($query) or die(mysql_error());
			echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$columns['Field']}<br>";
		}
	}
}

echo "<hr><h1>Done!</h1>";

关于php - WordPress DB字符集从utf8mb4更改为utf8导致错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40200315/

10-13 00:54