python mysql database connection - coding problems

Coding problems

1. Connect database statement

When using the mysql database pycharm connected locally, taking into account that the database statements completed, the problem of a troubled afternoon is connected statement did not join the encoding settings.

db = pymysql.connect(host='localhost', user='root', passwd='****', db='*****', charset='utf8')

Notably in the above code is, charset = 'utf8', can not be written utf8

2.pycharm change the encoding

If the two sides to determine their coding are correct, you can change the connections of the corresponding files under the project, as the path,

Will be one of

                if encoding is not None:
                    data = data.decode(encoding)

Changed

                if encoding is not None:
                    data = data.decode(encoding,'ignore')

If you want to change the interface code, the change process is as follows:

3. Change the database coding

Just change the character set can be shown

4. Other

In the search process, a method that is also mentioned, will change your computer's user name Chinese English alphabet, try not personally, I do not know the degree feasible.

Guess you like

Origin www.cnblogs.com/Qi77/p/12514632.html