mysqldump 并使用特殊字符进行恢复。 øæåØÆÅ

发布于 2024-09-16 02:40:29 字数 600 浏览 17 评论 0原文

在本地,我这样做是为了转储和移动数据库,将 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 技术交流群。

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

发布评论

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

评论(9

鹊巢 2024-09-23 02:40:47

对我有用的唯一方法是在 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.

撩动你心 2024-09-23 02:40:46

也许只需将表复制到 $newDatabase 作为 latin1 即可。
然后,对于每个表,执行:

ALTER TABLE table CONVERT TO CHARACTER SET utf8 COLLATE utf8_swedish_ci

Perhaps just copy the tables to $newDatabase as latin1.
Then, for each table, execute:

ALTER TABLE table CONVERT TO CHARACTER SET utf8 COLLATE utf8_swedish_ci
不寐倦长更 2024-09-23 02:40:45

您是否尝试过不使用 iconv 步骤?

以下是我在转储 UTF-8 数据库时使用的方法:

mysqldump \
    -u $DB_USER -p"$DB_PASS" \
    --default-character-set=Latin1 \
    --result-file=$DATAFILE

以及恢复:

mysql -u $DB_USER -p"$DB_PASS" \
    --default-character-set=latin1 < $DATAFILE

Have you tried it without the iconv step?

Here's what I use when dumping UTF-8 databases:

mysqldump \
    -u $DB_USER -p"$DB_PASS" \
    --default-character-set=Latin1 \
    --result-file=$DATAFILE

And to restore:

mysql -u $DB_USER -p"$DB_PASS" \
    --default-character-set=latin1 < $DATAFILE
等数载,海棠开 2024-09-23 02:40:43

这对我有用:

  1. ssh 服务器并连接。
  2. 创建数据库转储运行

mysqldump -h my_guid.cloud.database.com -u my_user -p my_database_name -r ~/my_db_backup.sql

控制台将提示并要求输入密码,您可以在其中输入密码,我的密码有特殊字符,所以我能够轻松运行这个命令

This worked for me:

  1. ssh the server and connect.
  2. create db dump running

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

万劫不复 2024-09-23 02:40:42

我的成功如下

mysql --default-character-set=utf8 -u ..

希望这会对您有所帮助。

I succeed as follows:

mysql --default-character-set=utf8 -u ..

May this will help you.

掌心的温暖 2024-09-23 02:40:40

确保客户端设置为 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.

狼性发作 2024-09-23 02:40:38

这为我解决了这个问题。

  1. 导入双重编码的input.sql

  2. 再次导出mysqldump -h "$DB_HOST -u "$DB_USER" -p"$DB_PASSWORD" -- opt --quote-names --skip-set-charset --default-character-set=latin1 "$DB_NAME" > output.sql

  3. 导入干净的output.sql

如何恢复mysqldump双编码的数据库

This fixed the issue for me.

  1. Import the double encoded input.sql

  2. 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

  3. Import clean output.sql

How to restore the database double encoded by mysqldump

讽刺将军 2024-09-23 02:40:36

我花了两天时间才知道
当我尝试使用 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

软糯酥胸 2024-09-23 02:40:34

尝试使用以下命令运行:

mysqldump -u root -p database -r output.sql

而不是使用箭头“>”重定向输出

Try to run with the following command:

mysqldump -u root -p database -r output.sql

instead of redirecting the output with arrow '>'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文