Django mysql 问题。。。报错如下

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django mysql 问题。。。报错如下相关的知识,希望对你有一定的参考价值。

E:\py\Django\BBSProject>python manage.py validate
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
385, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
354, in execute
django.setup()
File "C:\Python27\lib\site-packages\django\__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 85, in popu
late
app_config = AppConfig.create(entry)
File "C:\Python27\lib\site-packages\django\apps\config.py", line 116, in creat
e
mod = import_module(mod_path)
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named commentsdjango.contrib

参考技术A 在settings.py中的INSTALLED_APPS中的参数comments记得加逗号,
类似这样'comments',
'django.contrib.admin',本回答被提问者采纳

django-mysql报错

在执行python3 manage.py migrate时报错:操作错误,某库未给某用户授权

django.db.utils.OperationalError: (1044, "Access denied for user ‘xxx‘@‘localhost‘ to database ‘xxx‘")

 

解决方案:

mysql -uroot -p  # 进入数据库
grant all privileges on *.* to root@"%" identified by ".";  # 添加授权
FLUSH PRIVILEGES;    # 刷新

重新执行: python3 manage.py migrate

报错

django.db.utils.OperationalError: (1045, "Access denied for user ‘root‘@‘127.0.0.1‘ (using password: YES)"

或者

django.db.utils.OperationalError: (1045, "Access denied for user ‘root‘@‘127.0.0.1‘ (using password: NO)"

这个问题有时候是说你连接数据库的账号密码可能是错误的,也有可能是mysqld服务挂了,

mysqld是服务,mysql是客户端。

mysqld其实是SQL后台程序(也就是MySQL服务器),它是关于服务器端的一个程序,mysqld意思是mysql daemon,在后台运行,监听3306端口,如果你想要使用客户端程序,这个程序必须运行,因为客户端是通过连接服务器来访问数据库的。你只有启动了mysqld.exe,你的mysql数据库才能工作。

mysql是一个客户端软件,可以对任何主机的mysql服务(即后台运行的mysqld)发起连接,mysql自带的客户端程序一般都在cmd或者终端下进行操作

 

查看mysqld的运行状态

# service mysqld status
2020-01-01T12:48:51.388671Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-01-01T12:48:51.388843Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2020-01-01T12:48:51.388894Z 0 [Note] mysqld (mysqld 5.7.22) starting as process 24215 ...
2020-01-01T12:48:51.394256Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

2020-01-01T12:48:51.394294Z 0 [ERROR] Aborting

2020-01-01T12:48:51.394315Z 0 [Note] Binlog end
2020-01-01T12:48:51.394393Z 0 [Note] mysqld: Shutdown complete

查看mysql日志

# cd /usr/local/mysql/data     以.err为后缀的即是它的日志

 

 

最终解决是给mysql root用户设置密码

# mysql> set password for 用户名@localhost = password(‘新密码‘); 

 

 

 

以上是关于Django mysql 问题。。。报错如下的主要内容,如果未能解决你的问题,请参考以下文章

Django报错“Did you install mysqlclient or MySQL-python?”的解决办法(前提:mysqlclient&MySQL都已经安装)

Python3启动django项目报错“NameError: name '_mysql' is not defined”

Django2.2连接MySQL问题解决

django引入模块报错

python,django,向mysql更新数据时save()报错不能用

Django启动报错Did you install mysqlclient or MySQL-python