Python page garbled characters in ubuntu and solutions (pycharm + mysql + ubuntu) thereisnodoubtthat are caused by encoding problems. Ensure that the encoding of mysql, pycharm and browsers is three-in-one. 1. Add a line of "#-*-coding: UTF-8-*-" class at the beginning of each python page :#! Usrbinpython #-*-codin
Python page garbled characters in ubuntu and solutions (pycharm + mysql + ubuntu) there is no doubt that is caused by Encoding Problems. Ensure that the encoding of mysql, pycharm and browsers is three-in-one. 1. Add a line of "#-*-coding: UTF-8-*-" class at the beginning of each python page :#! /Usr/bin/python #-*-codin
Python page garbled characters in ubuntu and solutions (pycharm + mysql + ubuntu)
There is no doubt that is caused by encoding problems. Ensure that the encoding of mysql, pycharm, and browser is three-in-one.
1. Add a line "#-*-coding: UTF-8-*-" at the beginning of each python page -*-"
Similar to this :#! /Usr/bin/python
#-*-Coding: UTF-8 -*-
2. Modify the pycharm encoding:
Setting-> File Encoding-> All Encoding methods are changed to UTF-8 (some tutorials on the Internet say IDE Encoding should be changed to GBK, because in windows, the default Encoding is GBK, while in ubuntu is utf8)
3. Modify the mysql encoding:
View your mysql code: After logging on, enter the command show variables like '% char %', for example, mysql> show variables like '% char %' and the default mysql code is displayed:
You can manually use the command set @ character_set_client = utf8 to modify it, but it does not seem permanent. We recommend that you directly modify the configuration file/etc/mysql/my. cnf.
Find the [client] and [mysql] and add the default-character-set = utf8,
Find [mysqld] and add this section below it
Init_connect = 'set collation_connection = utf8_unicode_ci'
Init_connect = 'set NAMES utf8'
Character-set-server = utf8
Collation-server = utf8_unicode_ci
Skip-character-set-client-handshake
Save and exit.
Restart mysql. Enter sudo service mysql restart in the shell command line
After the restart, log on to mysql and check the encoding (command show variables like '% char %'). UTF-8 is returned, except for filesystem (My character_set_database or GBK, but it does not seem to have any impact)
The tutorial for modifying the mysql configuration file found on the Internet is to add the default-character-set = utf8 and init_connect = 'set NAMES utf8' sentences under [mysqld, however, it turns out that mysql cannot be restarted after it is added. You may try it.
4. Modify the browser encoding. Generally, Firefox is used in ubuntu. The modification method is as follows:
Edit-> preferences-> content-> font and color "advanced" button-> default character encoding changed to UTF8
If all of the above are correct and garbled characters still occur, try to check:
1. On the Firefox browser page, right-click to view the page information-> General-> to see if the encoding is utf8. If not, click View-> character encoding-> utf8 in the upper-left corner of Firefox browser.
2. If the character code on the page is utf8, make sure that the data stored in mysql is not garbled: log on to mysql and check whether the data in your table is garbled. mysql-> select * from yourTableName, in case of garbled characters, use the insert into statement to insert Chinese characters, and then check whether the data is properly displayed in the browser.