如何一次性将排序规则更改为utf8_bin

发布于 2024-10-14 10:58:14 字数 214 浏览 3 评论 0原文

我已将所有数据库表的排序规则设置为 latin1_swedish_ci,现在我意识到我应该使用 utf8_binutf8_general_ci

如何一次性将表中的排序规则更改为 utf8_binutf8_general_ci?我可以使用查询或其他东西吗?

I have set up the Collation of all my database tables as latin1_swedish_ci and now I realise that I should use utf8_bin or utf8_general_ci.

How can I change the Collation in the tables to utf8_bin or utf8_general_ci in one go? Can I use a query or something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

沫尐诺 2024-10-21 10:58:14

您只需要在每个表上运行 ALTER,如下所示:

ALTER TABLE <table name> COLLATE utf8_general_ci;

如果您还需要更新现有的字符编码(听起来不太可能),您可以使用:

ALTER TABLE <table name> CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

You'll simply need to run an ALTER on each of the tables as follows:

ALTER TABLE <table name> COLLATE utf8_general_ci;

If you also need to update the existing character encoding (unlikely by the sounds of things), you can use:

ALTER TABLE <table name> CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
挽容 2024-10-21 10:58:14

您还可以使用以下命令更新数据库排序规则:

ALTER DATABASE  `DATABASE_NAME` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci

You can also update the database collation with:

ALTER DATABASE  `DATABASE_NAME` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci
戒ㄋ 2024-10-21 10:58:14

您可以使用ALTER TABLE更改表的排序规则:

alter table table_name collate=utf8_general_ci;

You can change the collation of a table with ALTER TABLE:

alter table table_name collate=utf8_general_ci;
潇烟暮雨 2024-10-21 10:58:14

这里有两种方法。第一个对我有用。从终端(只需记住之前备份即可。)

mysql --database=dbname -B -N -e "SHOW TABLES"  | awk '{print "ALTER TABLE", $1, "CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"}' | mysql --database=dbname &

来源:Commandlineinfu.com

来自 MySQL
你必须使用 Concat 命令

SELECT CONCAT('ALTER TABLE `', tbl.`TABLE_SCHEMA`, '`.`', tbl.`TABLE_NAME`, '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;') FROM `information_schema`.`TABLES` tbl WHERE tbl.`TABLE_SCHEMA` = 'dbname'

Here are two ways. First one worked for me. From the terminal (Just remember to backup before.)

mysql --database=dbname -B -N -e "SHOW TABLES"  | awk '{print "ALTER TABLE", $1, "CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"}' | mysql --database=dbname &

Source: Commandlineinfu.com

From MySQL
you will have to use the Concat command

SELECT CONCAT('ALTER TABLE `', tbl.`TABLE_SCHEMA`, '`.`', tbl.`TABLE_NAME`, '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;') FROM `information_schema`.`TABLES` tbl WHERE tbl.`TABLE_SCHEMA` = 'dbname'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文