django-mysql报错

时间:2021-07-28 02:47:05

在执行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 [email protected]"%" 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(‘新密码‘);