utf8 garbled when importing into mysql

后端 未结 4 822
隐瞒了意图╮
隐瞒了意图╮ 2020-12-23 14:28

Importing UTF8-encoded data into mysql is not working for me. UTF8 characters are corrupted. For example Nöthnagel is displayed as Nöthnagel

相关标签:
4条回答
  • 2020-12-23 15:14

    Use this command for import utf8 table to database :

    mysql -u USERNAME  -pPASSWORD --default_character_set utf8  DATABASE < file.sql
    
    0 讨论(0)
  • 2020-12-23 15:22

    I think it might have something to do with collation as well, but I'm not sure. In my case it certainly did, since I had to support cyrillic.
    Try this, worked for me:

    1. Set initial collation while creating the target database to utf8_general_ci

    2. Add SET NAMES 'utf8' COLLATE 'utf8_general_ci'; to the top of your sql file

    3. Run mysql -u root -p --default-character-set=utf8 yourDB < yourSQLfile.sql

    One more thing, in order to properly get the UTF-8 data form your database, you'll have to modify your connection string as well. For example:

    mysql.url=jdbc:mysql://localhost:3306/nbs?useJvmCharsetConverters=false&useDynamicCharsetInfo=false&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&useEncoding=true

    Additionally, take a look at what my problem was.

    0 讨论(0)
  • 2020-12-23 15:27

    The problem was solved by adding this at the top of the sql file:

    SET NAMES utf8;
    
    0 讨论(0)
  • 2020-12-23 15:27

    I had a similar problem. There are a number of variables that should be UTF8, not only the database, those include the client, the connection, ther server ...etc.

    The solution to your problem is described in this article. The described solution is portable, so it does not only work for utf8, but for all other character sets. You may need to modify it to fit your needs.

    0 讨论(0)
提交回复
热议问题