Mysql基本操作 show databases; use test; show tables; show global variables like 'port'; create databse guest character set utf8; python操作mysql 主要方法步骤 connect():建立数据库连接 cursor():获取数据库操作游标 execute():执行sql语句. commit():提交数据库执行 close():关闭数据库连接 在setting中配置 python数据库配置 DATABASES = { 'default':{ 'ENGINE':'django.db.backends.mysql', 'HOST':'localhost', 'PORT':'3306', 'NAME':'guest', 'USER':'root', 'PASSWORD':'123456', 'OPTIONS':{ 'init_command':"SET sql_mode='STRICT_TRANS_TABLES'", }, } } 然后进行数据迁移 python manage.py migrate 报如下的错误 settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details. 可能是拼写错,...不好意思眼神不好 再次报错: raise ImproperlyConfigured ('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__) django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3. 参考解决: https://blog.csdn.net/qq_35304570/article/details/79674449 然后数据库也报错了,因为使用mysql8.0,版本问题 参看文档如下: https://blog.csdn.net/p_xiaobai/article/details/85334875 然后又报错 File "C:\Users\mi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\mysql\operations.py", line 146, in last_executed_query query = query.decode(errors='replace') AttributeError: 'str' object has no attribute 'decode' 网上搜索了一下,没有有用的办法,大概是类型转换问题 我直接在对应文档,改了一下就可以了 query = 'replace' #query.decode(errors='replace') 好吧完成了,这些东西都是坑啊...