MongoDB mongorestore 失败:locale::facet::_S_create_c_locale 名称无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19100708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 13:26:24  来源:igfitidea点击:

MongoDB mongorestore failure: locale::facet::_S_create_c_locale name not valid

mongodblocaleubuntu-12.04mongodumpmongorestore

提问by Luca Anceschi

I created a dump with mongodump on computer A (ubuntu 12.04 server). I moved it to computer B (ubuntu 12.04 server) and typed:

我在计算机 A(ubuntu 12.04 服务器)上用 mongodump 创建了一个转储。我将它移到计算机 B(ubuntu 12.04 服务器)并输入:

mongorestore -db db_name --drop db_dump_path

mongorestore -db db_name --drop db_dump_path

It failed and it reported:

它失败了,并报告:

connected to: 127.0.0.1
terminate called after throwing an instance of 'std::runtime_error'
what(): locale::facet::_S_create_c_locale name not valid
Aborted

连接到:127.0.0.1
在抛出“std::runtime_error”
what()实例后调用终止:locale::facet::_S_create_c_locale 名称无效
中止

I've successfully accomplished this operation before and this strange behavior has never occurred. What do I need to do to fix this?

我之前已经成功完成了这个操作,从来没有发生过这种奇怪的行为。我需要做什么来解决这个问题?

采纳答案by Luca Anceschi

Actually it isn't strictly related to MongoDB. Somehow the language on computer B was not defined correctly. I managed to fix it by typing:

实际上它与MongoDB没有严格的关系。不知何故,计算机 B 上的语言定义不正确。我设法通过键入来修复它:

sudo locale-gen en_US en_US.UTF-8
sudo locale-gen it_IT it_IT.UTF-8
sudo locale-gen xx_xx xx_XX.UTF-8 ...
sudo dpkg-reconfigure locales

sudo locale-gen en_US en_US.UTF-8
sudo locale-gen it_IT it_IT.UTF-8
sudo locale-gen xx_xx xx_XX.UTF-8 ...
sudo dpkg-reconfigure locales

These commands will generate and configure the needed locales. After those steps mongorestore got back working as usual.

这些命令将生成和配置所需的语言环境。在这些步骤之后 mongorestore 恢复正常工作。

回答by keisar

On my distro "locale-gen" was not installed and it turned out all I had to do is set the LC_ALL environment variable. so the following command fixed it:

在我的发行版上没有安装“locale-gen”,结果我要做的就是设置 LC_ALL 环境变量。所以以下命令修复了它:

export LC_ALL="en_US.UTF-8"

hopefully it will help someone else...

希望它会帮助别人......

回答by josch

Exporting LC_ALL="en_US.UTF-8"only works if you have the en_USlocale installed. If you want to avoid installing the localespackage (or its equivalent on distributions other than Debian derivatives), then you can instead use:

LC_ALL="en_US.UTF-8"仅当您安装了en_US语言环境时,导出才有效。如果您想避免安装该locales软件包(或在 Debian 衍生版以外的发行版上的等价物),那么您可以改为使用:

export LC_ALL=C.UTF-8

which will not require any extra locale data.

这不需要任何额外的语言环境数据。

回答by Alex

If you are using a Mac OSX and SSH this might be issued by wrong LC_CTYPE.

如果您使用的是 Mac OSX 和 SSH,这可能是由错误的 LC_CTYPE 发出的。

$ locale 
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE=UTF-8
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Unset the wrong var.

取消设置错误的变量。

$ unset LC_CTYPE 

Check whether locale is working fine.

检查语言环境是否工作正常。

$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Now mongo also should do fine.

现在 mongo 也应该做得很好。

回答by Sebastien Lorber

To make the fix permanent you can edit one of those files:

要使修复永久化,您可以编辑这些文件之一:

  • sudo vim /etc/default/locale
  • sudo vim /etc/environment
  • 须藤vim /etc/default/locale
  • 须藤vim /etc/environment

And add the line LC_ALL="en_US.UTF-8"

并添加行 LC_ALL="en_US.UTF-8"

回答by Daniele Vrut

Got same problem on debian 7 without locale-gen (command not found) installed.

在没有安装 locale-gen(未找到命令)的 debian 7 上遇到了同样的问题。

I solved this way:

我是这样解决的:

su
apt-get install locales
dpkg-reconfigure locales # select locales you want!

Now mongodb should start.

现在 mongodb 应该启动了。

Source

来源