MySQL - 俄语字符显示不正确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4316290/
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-08-31 17:51:53  来源:igfitidea点击:

MySQL - Russian characters display incorectly

mysqlencodingcyrillic

提问by Mike

I have to make an russian version of a website, but I can't find out, how to insert russian characters into Database.

我必须制作一个网站的俄语版本,但我不知道如何将俄语字符插入到数据库中。

I tryed almost every possible coding, but it only shows:

我尝试了几乎所有可能的编码,但它只显示:

???????? ?????????? ??????? ??????? ? ????? ?? ????????????? ? ???????, ??????? ????? ??????? ???????? ????? .??? ??????????? ???????? ????? ?? ????? ?????????? ? ????? ????????.
??????????? ?????? ?? ???????? ????? ?? 20 ???????. ???????? ??? ?? ??????????? ?????????????? ????? ? ????????????? ??????? ??????. ? ???????, ? ??????? ? ?.?. 

回答by meder omuraliev

  1. Make sure the database charset/collation is UTF-8
  2. On the page you insert these russian characters ( the form, textarea ), make sure the encoding is UTF-8, by setting Content-Type to text/html; charset=utf-8. Enter in russian text directly to the form input.
  3. On the processing page that handles this form, which inserts it into the database, make sure to do SET NAMES utf8so it's stored as UTF-8 beforeyou insert the data, in a separate query beforehand.
  4. When you render the content from the database in a view, make sure the Content-Typeis text/html; charset=utf-8.
  1. 确保数据库字符集/排序规则为 UTF-8
  2. 在您插入这些俄语字符(表单, textarea )的页面上,通过将 Content-Type 设置为 ,确保编码为 UTF-8 text/html; charset=utf-8。直接在表单输入中输入俄文文本。
  3. 在处理此表单的处理页面上,将其插入到数据库中,确保插入数据之前将其SET NAMES utf8存储为 UTF-8 ,事先在单独的查询中。
  4. 当你从渲染视图中的数据库中的内容,确保Content-Typetext/html; charset=utf-8

Make sure that the content-type is notwindows-1251 or iso-8859-1/latin1. Make sure the database charset/collation is NOT ISO-8859-1/Latin1.

确保内容类型不是windows-1251 或 iso-8859-1/latin1。确保数据库字符集/排序规则不是 ISO-8859-1/Latin1。

回答by Shubham Chopra

For storing russian characters in db your db should support UTF-8 encoding. Modify your table with below query to enable UTF-8 encoding.

为了在 db 中存储俄语字符,您的 db 应该支持 UTF-8 编码。使用以下查询修改您的表以启用 UTF-8 编码。

ALTER TABLE t1 CONVERT TO CHARACTER SET utf8