mysql - 哪个是更改大数据表字符集的更好方法?

标签 mysql sql character-encoding

在我的生产数据库中,警报相关表是使用默认字符集“latin”创建的,因此我们在尝试时遇到错误 在表中插入日语字符。我们需要将表和列的默认字符集更改为 UTF8。 由于这些表有大量数据,Alter 命令可能会花费很多时间(在我的本地数据库中使用相同数量的数据需要 5 小时) 并锁定会导致数据丢失的表。我们能否设计一种机制,将 Charset 更改为 UTF8 而不会丢失数据。

对于巨大的数据表,哪种更改字符集的方法更好?

最佳答案

我在 mysql 手册上找到了这个 http://dev.mysql.com/doc/refman/5.1/en/alter-table.html :

In most cases, ALTER TABLE makes a temporary copy of the original table. MySQL waits for other operations that are modifying the table, then proceeds. It incorporates the alteration into the copy, deletes the original table, and renames the new one. While ALTER TABLE is executing, the original table is readable by other sessions. Updates and writes to the table that begin after the ALTER TABLE operation begins are stalled until the new table is ready, then are automatically redirected to the new table without any failed updates

所以是的——在执行此操作时尽量减少停机时间是很棘手的。这取决于您的表的使用情况,是否有更多的读/写?

我能想到的一种方法是使用某种复制。因此,创建一个使用 UTF-8 的新警报表,并找到一种方法将原始表复制到新表而不影响可用性/吞吐量。当复制完成(或足够接近)时,通过重命名来切换表?

当然,这说起来容易做起来难——如果可能的话,还需要更多的学习。

关于mysql - 哪个是更改大数据表字符集的更好方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14516003/

相关文章:

python - 如何更改Python中for循环的计数器?

php - 使用 PHP 发送一封电子邮件,其中包含从数据库中获取的信息

php - 从 MySQL 中按月和年分组的时间戳列中获取记录

mysql - 如何删除所有外键约束?

PHP MySQLI 准备语句在执行时返回 false

mysql - 非英语语言的子字符串

php - 登录脚本 - 计算行数或使用 COUNT ('column' )

php - 哪种方法最好始终使用 file_put_contents 写入数据或检查数据是否更改然后更新文件?

Python tkinter Entry 小部件显示条形字符而不是换行符

MySQL 工作台。数据以乱码而不是希伯来语显示