如何将postgreSQL中的db转换为utf8? [英] How to convert a db in postgreSQL to utf8?

查看:954
本文介绍了如何将postgreSQL中的db转换为utf8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



那么什么是我的项目的postgreSQL中的一个数据库,只是意识到它是在SQL_ASCII编码,这意味着无编码最简单的方法转换为utf8?我知道db应该在latin1,转换会损坏内容吗?



谢谢!

解决方案

转换为UTF8不会损害您的资料,因为我相信没有字元无法翻译。



重新构建数据库,即转储它,创建一个utf8数据库,然后将转储恢复到该新数据库。

  postgres pg_dump --encoding utf8 main -f main.sql 
createdb -E utf8 newMain
psql -f main.sql -d newMain



然后,当您满意新的UTF8与您的数据匹配时,您当然可以重命名数据库。


I've just got a db in postgreSQL for my project and just realized it's in SQL_ASCII encoding, which means "no encoding" I think.

So what is the simplest way to convert this to utf8? And I know the db should be in latin1, does the conversion will damage the content?

Thanks!

解决方案

Converting to UTF8 should not damage your data since I believe there are no characters which don't translate.

Your best bet is to re-build your database, that is dump it, create a utf8 database then restore the dump to that new database.

postgres pg_dump --encoding utf8 main -f main.sql
createdb -E utf8 newMain
psql -f main.sql -d newMain

You can then of course rename the databases once you are happy that the new UTF8 one matches your data.

这篇关于如何将postgreSQL中的db转换为utf8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆