如何将数据库中的所有字段从latin1_swedish_ci更改为utf8_general_ci?

时间:2022-03-10 20:15:27

The title saiz it all, right? :)

这个头衔是全部,对吧? :)

Details: I'm looking for a SQL query I can use in phpmyadmin. Need to Change all my fields in one database from latin1_swedish_ci to utf8_general_ci

详细信息:我正在寻找可以在phpmyadmin中使用的SQL查询。需要将一个数据库中的所有字段从latin1_swedish_ci更改为utf8_general_ci

2 个解决方案

#1


1  

The main problem in your case is when you change the collation/character set from the table the data inside the table are latin1 and the table is utf8 until then.

在您的情况下,主要问题是当您从表中更改排序/字符集时,表中的数据是latin1,并且表是utf8直到那时。

What you can try is to make a dump of the table with the old character set.

您可以尝试使用旧字符集转储表。

mysqldump -uuser -p --default-character-set=latin1 dbname > dump.sql

and then import the database with the new character set like this:

然后使用新的字符集导入数据库,如下所示:

mysql -uuser -p --default-character-set=utf8 dbname_test < dump.sql

To test i would import the dump to a test database. If the characters are not correct after the import. Use an Editor like pspad or notepad++ and change the file encoding to UTF-8. After this you can try to import another time.

要测试我会将转储导入测试数据库。如果导入后字符不正确。使用像pspad或notepad ++这样的编辑器,将文件编码更改为UTF-8。在此之后,您可以尝试导入另一个时间。

The most times encodings are very annoying but i hope you can solve it.

大多数时候编码非常烦人,但我希望你能解决它。

When you only have phpmyadmin use the "Export" function and make the same with phpmyadmin. Export in the actual encoding and try to import in the new encoding but then you have to change the file encoding i think.

当你只有phpmyadmin使用“导出”功能,并使用phpmyadmin。以实际编码导出并尝试以新编码导入,但是您必须更改我认为的文件编码。

#2


1  

Change the default collation to utf8_general_ci in MySql:

在MySql中将默认排序规则更改为utf8_general_ci:

Open the my.ini file. (C:\xampp\mysql\bin\my.ini)
Find the text [mysqld] and add the below lines.

[mysqld]

character-set-server = utf8

character-set-server = utf8

collation-server = utf8_general_ci

collat​​ion-server = utf8_general_ci

The above two lines will select a character set and collation at server startup. These settings apply server-wide and apply as the defaults for databases created by any application, and for tables created in those databases. 

#1


1  

The main problem in your case is when you change the collation/character set from the table the data inside the table are latin1 and the table is utf8 until then.

在您的情况下,主要问题是当您从表中更改排序/字符集时,表中的数据是latin1,并且表是utf8直到那时。

What you can try is to make a dump of the table with the old character set.

您可以尝试使用旧字符集转储表。

mysqldump -uuser -p --default-character-set=latin1 dbname > dump.sql

and then import the database with the new character set like this:

然后使用新的字符集导入数据库,如下所示:

mysql -uuser -p --default-character-set=utf8 dbname_test < dump.sql

To test i would import the dump to a test database. If the characters are not correct after the import. Use an Editor like pspad or notepad++ and change the file encoding to UTF-8. After this you can try to import another time.

要测试我会将转储导入测试数据库。如果导入后字符不正确。使用像pspad或notepad ++这样的编辑器,将文件编码更改为UTF-8。在此之后,您可以尝试导入另一个时间。

The most times encodings are very annoying but i hope you can solve it.

大多数时候编码非常烦人,但我希望你能解决它。

When you only have phpmyadmin use the "Export" function and make the same with phpmyadmin. Export in the actual encoding and try to import in the new encoding but then you have to change the file encoding i think.

当你只有phpmyadmin使用“导出”功能,并使用phpmyadmin。以实际编码导出并尝试以新编码导入,但是您必须更改我认为的文件编码。

#2


1  

Change the default collation to utf8_general_ci in MySql:

在MySql中将默认排序规则更改为utf8_general_ci:

Open the my.ini file. (C:\xampp\mysql\bin\my.ini)
Find the text [mysqld] and add the below lines.

[mysqld]

character-set-server = utf8

character-set-server = utf8

collation-server = utf8_general_ci

collat​​ion-server = utf8_general_ci

The above two lines will select a character set and collation at server startup. These settings apply server-wide and apply as the defaults for databases created by any application, and for tables created in those databases.