idea连接mysql出现1045_mysql - mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'...

I've started working with django, and here is the error on 'runserver' after setting up 'DATABASES' in settings.py

mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")

My settings.py portion of code:

DATABASES = {

'default': {

'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.

'NAME': 'my_site', # Or path to database file if using sqlite3.

'USER': 'root', # Not used with sqlite3.

'PASSWORD': 'root', # Not used with sqlite3.

'HOST': '', # Set to empty string for localhost. Not used with sqlite3.

'PORT': '', # Set to empty string for default. Not used with sqlite3.

}

}

I've created 'my_site' database and privileges are set in the right way (root has all privileges). I've done this operations with 'phpmyadmin'.

What goes wrong?

mysql

django

privileges

|

this question

edited Apr 16 '12 at 20:54 asked Apr 16 '12 at 20:38

Massimo Variolo 2,026 3 18 43

|

5 Answers

5

Run in console

mysql> grant all privileges on *.* to root@localhost identified by 'password' with grant option;

|

this answer answered Feb 4 '13 at 9:35

Akhilraj N S 4,945 4 18 28      i actually want to run this command through python. But I get access denied. Any idea how to automate this? Thanks –

Ankur Bhatia Oct 31 '16 at 16:02

|

I had been struggling this problem for two days and i finally found whats wrong. steps to solve this problem are-

Your settings.py file must look like-

DATABASES = {

'default': {

'ENGINE': 'django.db.backends.mysql',

'NAME': 'django_db', #Name of database you created in localhost

'USER': 'root',

'PASSWORD':'',

'HOST': '',

'PORT': '',

} }

Note:-The password and username given above is of my localhost you can change it.

create a database in localhost let name it django_db (for this you must be having lamp/wamp/Xampp installed in your system)

Edit the file settings.py and save the password you require to open your database in DATABASES field as given below in the code.

open terminal.

run command-> workon env_name

Now cd app_name eg. cd mysite

step 3 and step 4 just tells to reach the folder where manage.py file found in your Application.

6.To check you are in right directory run command ls -l. If you find manage.py file then everything is right move forwardSQL database that I installed using easyPHP on my windows machine, using the cmd line. I am going to the \mysql\bin and entering the command: mysql -u root in order to log in, but I am getting the following message: error 1045 (28000) acce

7.python manage.py migrate

If you are having any error like- "No module named MySQLdb" in running above command you can visit the link

8.python manage.py syncdb

9.python manage.py runserver

10.You will be asked for username and password for your Django admin give it.

11.check you are having some tables in your database in localhost at `http://localhost/phpmyadmin

|

this answer

edited Mar 14 '15 at 15:35 answered Jan 20 '15 at 9:54

Rahul Satal 371 1 3 22

|

The instruction said to add the username with the SQL statement as:

GRANT SELECT, INSERT, UPDATE, DELETE, LOCK TABLES ON winestores.* TO username@127.0.0.1 IDENTIFIED by 'password';

After doing this as root, I quit and tried to log back in with the new user. I got the ERROR 1045. I fixed it by logging back in as root and reissuing the SQL statement again except with username@localhost. It worked! I don't know why? Maybe it is the difference between IPs of '127.0.0.1' and 'localhost'???

|

this answer answered Apr 16 '12 at 20:44

hjpotter92 47.1k 16 63 95      doesn't work for me. –

Massimo Variolo Apr 16 '12 at 21:32

|

your DB doesn't recognize your root user and password. If you can go to the phpmyAdmin and try to create a different user and password and assign to the DB, if that is not working try to create but console with create user, and grant all.

|

this answer answered Apr 16 '12 at 20:42

jcho360 3,279 1 7 20      done: didn't work –

Massimo Variolo Apr 16 '12 at 21:27

|

For anyone encountering this issue - check to make sure that the database user host is localhost . If set to %, it won't work, you will need to add localhost or change your overall security settings.

|

this answer answered Nov 4 '14 at 6:51

Dennis Kioko 404 2 10 25

|

from the live site through MAMP, and I received an error message when trying to connect to phpMyAdmin: #1045 - Access denied for user 'root'@'localhost' (using password: YES) I have a couple local WP installations running already, and I'm a

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值