mysqldump 并使用特殊字符进行恢复。 øæåØÆÅ
在本地,我这样做是为了转储和移动数据库,将 silverstripe 2.3 升级到 2.4:
mysqldump --opt --default-character-set=latin1 --skip-set-charset --user=$root -p$password $oldDatabase -r db.sql
iconv -f LATIN1 -t UTF8 db.sql > db_utf.sql
CREATE DATABASE $newDatabase CHARACTER SET utf8 COLLATE utf8_swedish_ci; FLUSH PRIVILEGES; GRANT ALL PRIVILEGES ON $newDatabase . * TO '$newUser'@'localhost'; FLUSH PRIVILEGES;
SET NAMES utf8; SOURCE db_utf.sql;
它可以工作,但在服务器 Ubuntu 8.04 上,使用 mysql Ver 14.12 Distrib 5.0.51a。 我得到了疯狂的 √∏
字符而不是 øæåØÆå
。
有人知道我哪里出错了吗?
Locally I do this to dump and move a database, upgrading silverstripe 2.3 to 2.4:
mysqldump --opt --default-character-set=latin1 --skip-set-charset --user=$root -p$password $oldDatabase -r db.sql
iconv -f LATIN1 -t UTF8 db.sql > db_utf.sql
CREATE DATABASE $newDatabase CHARACTER SET utf8 COLLATE utf8_swedish_ci; FLUSH PRIVILEGES; GRANT ALL PRIVILEGES ON $newDatabase . * TO '$newUser'@'localhost'; FLUSH PRIVILEGES;
SET NAMES utf8; SOURCE db_utf.sql;
And it works, but on the server Ubuntu 8.04, with mysql Ver 14.12 Distrib 5.0.51a.
I get crazy √∏
characters instead of øæåØÆå
.
Anyone know where I've gone wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
对我有用的唯一方法是在 phpmyadmin 中将 utf-8 表导出为 latin-1 (文件字符集:iso-8859-1)。
用notepad++打开导出的文件
转换为UTF8(带BOM)
然后上传文件并使用SOURCE dump.sql导入。
Only way that worked for me was to export the utf-8 tables as latin-1 (character set of file: iso-8859-1) in phpmyadmin.
Open the exported file in notepad++
convert to UTF8 (with BOM)
Then upload file and import with SOURCE dump.sql.
也许只需将表复制到 $newDatabase 作为 latin1 即可。
然后,对于每个表,执行:
Perhaps just copy the tables to $newDatabase as latin1.
Then, for each table, execute:
您是否尝试过不使用 iconv 步骤?
以下是我在转储 UTF-8 数据库时使用的方法:
以及恢复:
Have you tried it without the
iconv
step?Here's what I use when dumping UTF-8 databases:
And to restore:
这对我有用:
mysqldump -h my_guid.cloud.database.com -u my_user -p my_database_name -r ~/my_db_backup.sql
控制台将提示并要求输入密码,您可以在其中输入密码,我的密码有特殊字符,所以我能够轻松运行这个命令
This worked for me:
mysqldump -h my_guid.cloud.database.com -u my_user -p my_database_name -r ~/my_db_backup.sql
The console will prompt and ask for the password and there you can type it, my pwd had special characters so i was able to run this command with ease
我的成功如下:
希望这会对您有所帮助。
I succeed as follows:
May this will help you.
确保客户端设置为 UTF8 非常重要。令人困惑的是,这与将数据库设置为 UTF8 不同。打开 /etc/my.cnf 并确保 [mysql] 下有 default-character-set = utf8 而不仅仅是 [mysqld]
现在您应该能够将 UTF8 转储直接通过管道传输到 mysql 客户端。我还建议在 mysqldump 命令上使用选项 --hex-blob,因为 mysqldump 并不完美。
It's very important to make sure the client is set to UTF8. Confusingly, it's not the same as setting your database to UTF8. Open /etc/my.cnf and make sure you have default-character-set = utf8 under [mysql] not just under [mysqld]
Now you should be able to pipe UTF8 dumps directly into the mysql client. I also recommend using the option --hex-blob on the mysqldump command as mysqldump is not perfect.
这为我解决了这个问题。
导入双重编码的input.sql
再次导出
mysqldump -h "$DB_HOST -u "$DB_USER" -p"$DB_PASSWORD" -- opt --quote-names --skip-set-charset --default-character-set=latin1 "$DB_NAME" > output.sql
导入干净的output.sql
如何恢复mysqldump双编码的数据库
This fixed the issue for me.
Import the double encoded input.sql
Export it again
mysqldump -h "$DB_HOST -u "$DB_USER" -p"$DB_PASSWORD" --opt --quote-names --skip-set-charset --default-character-set=latin1 "$DB_NAME" > output.sql
Import clean output.sql
How to restore the database double encoded by mysqldump
我花了两天时间才知道
当我尝试使用 mysqldump 以阿拉伯语导出数据库时,我遇到了同样的问题并解决了它
每次你在记事本++中打开输出文件时,它的编码都是ansi,你需要它是utf-8我的导出和导入代码如下,事实证明我是对的,但我正在终端上检查数据库,但终端不支持编码,我只是尝试用 phpmyadmin 检查它,它的好处是不要尝试在记事本++中打开文件
或者直接尝试您的应用程序,它会起作用。
导出命令
mysqldump -uuser -ppassword --default-character-set=utf8 dbname >输出文件 //或者即使你使用 -r 而不是 >没有区别
导入命令
<代码>
mysql -uuser -ppassword --default-character-set=utf8 数据库名 < outputfille // 请记住这会覆盖现有数据库
It took me Two days to find out
I had the same problem and solved it when trying to export a database in arabic using mysqldump
and each time you open the outputfile in notepad++ its encoding is in ansi and you need it to be utf-8 my code for export and import was as follows it turns out i was right but i was checking the database on the terminal but the terminal doesn't support encoding and i just tried checking it with phpmyadmin and its good don't try to open the file in notepad++
or just try your application directly it will work.
export command
mysqldump -uuser -ppassword --default-character-set=utf8 dbname > outputfile //or even if you use -r instead of > no difference
import command
mysql -uuser -ppassword --default-character-set=utf8 dbname < outputfille // please take in mind this does override existing database
尝试使用以下命令运行:
而不是使用箭头“>”重定向输出
Try to run with the following command:
instead of redirecting the output with arrow '>'