MySQL: django.db.utils.OperationalError: (1698, "Access denied for user 'root'@'localhost'") with correct username and pw
MySQL: django.db.utils.OperationalError: (1698, "Access denied for user 'root'@'localhost'") with correct username and pw
我在使用mysql时有django.db.utils.OperationalError: (1698, "Access denied for user 'root'@'localhost'")
。用户名和密码正确:
DB_HOST = '127.0.0.1'
DB_USER = 'root'
DB_PASSWORD = ''
我可以以 root 身份登录 mysql:
$ sudo mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
但不像 cchilders
:
$ mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
这可能会导致问题。上次我安装 mysql 时并没有发生这种情况,所以这对我来说没有意义。我的客户很好:
$ pip3 freeze
Django==1.10.5
mysqlclient==1.3.9
我怎样才能让 mysql 成为我的普通用户 运行,这样我就可以在终端中 运行 django?谢谢
肮脏的解决方案:
没有任何修复,总是运行 mysql as sudo
创建一个非根 SQL 用户并更改 Django settings.py 文件中的 DB_USER 变量
您可以在服务器上以 root
身份登录的原因是您可能在 /root
的 .my.cnf
文件中指定了密码(即 root
用户的主目录)。检查那里是否有密码并将其用于 cchilders
。然后,您可以创建一个特定于 django 的应用程序用户,以确保 django 应用程序仅 reads/writes/etc。到它需要访问的数据库,而不是通过 root
mysql 用户访问。
create user 'django'@'localhost' identified by 'django-user-password';
grant usage on *.* to 'django'@'localhost';
grant all privileges on django-database-1.* to 'django'@'localhost';
我在使用mysql时有django.db.utils.OperationalError: (1698, "Access denied for user 'root'@'localhost'")
。用户名和密码正确:
DB_HOST = '127.0.0.1'
DB_USER = 'root'
DB_PASSWORD = ''
我可以以 root 身份登录 mysql:
$ sudo mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
但不像 cchilders
:
$ mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
这可能会导致问题。上次我安装 mysql 时并没有发生这种情况,所以这对我来说没有意义。我的客户很好:
$ pip3 freeze
Django==1.10.5
mysqlclient==1.3.9
我怎样才能让 mysql 成为我的普通用户 运行,这样我就可以在终端中 运行 django?谢谢
肮脏的解决方案:
没有任何修复,总是运行 mysql as sudo
创建一个非根 SQL 用户并更改 Django settings.py 文件中的 DB_USER 变量
您可以在服务器上以 root
身份登录的原因是您可能在 /root
的 .my.cnf
文件中指定了密码(即 root
用户的主目录)。检查那里是否有密码并将其用于 cchilders
。然后,您可以创建一个特定于 django 的应用程序用户,以确保 django 应用程序仅 reads/writes/etc。到它需要访问的数据库,而不是通过 root
mysql 用户访问。
create user 'django'@'localhost' identified by 'django-user-password';
grant usage on *.* to 'django'@'localhost';
grant all privileges on django-database-1.* to 'django'@'localhost';