2012-04-16 10 views
12

djangoの作業を開始しましたが、セットアップ後に 'runserver' settings.pymysql_exceptions.OperationalError:(1045、 "ユーザー 'root' @ 'localhost'(パスワードは:YESを使用して)アクセスが拒否されました)

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

中のデータベース「コードの私のsettings.py部分:

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. 
    } 

} 

私は「my_site」データベースと権限が正しい方法で設定されて作成した(ルートがすべての権限を持っています)。 私はこの操作を 'phpmyadmin'で行っています。

何が問題になるのですか?

答えて

13

ラン - データベースユーザホストlocalhostであることを確認してください。 %に設定した場合は動作しません。localhostを追加するか、全体のセキュリティ設定を変更する必要があります。

+0

私は実際にこのコマンドをpythonで実行したいと思っています。しかし、私はアクセスが拒否されます。これをどのように自動化するのか?ありがとう –

0

DBはrootユーザーとパスワードを認識しません。 phpmyAdminにアクセスして、別のユーザーとパスワードを作成してDBに割り当てようとすると、それが動作していない場合は、create userでコンソールを作成し、すべてを許可してみてください。 dev.mysql.comに読んよう

+0

を訪問することができますが: –

1

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

GRANT SELECT, INSERT, UPDATE, DELETE, LOCK TABLES ON winestores.* TO [email protected] 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 [email protected] . It worked! I don't know why? Maybe it is the difference between IPs of '127.0.0.1' and 'localhost'???

。この問題に遭遇した人のためのコンソール

mysql> grant all privileges on *.* to [email protected] identified by 'password' with grant option; 
+0

は私のために動作しません動作しませんでした。 –

0

3

2日間苦労した後、私はついに間違ったことを見つけました。

Your settings.py file must look like-

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.mysql', 
     'NAME': 'django_db', #Name of database you created 
     'USER': 'root',  #Username of database you created 
     'PASSWORD':'',   #Password of database you created 
     'HOST': '', 
     'PORT': '', 
    } } 

注are- DjangoのサイトのMySQLデータベースをセットアップする 全体の手順:上記-Theパスワードとユーザー名、あなたはあなたにそれを変更する必要があり、私はlocalhostです。

  1. create a database in localhost let name it django_db (for this you can use lamp/wamp/Xampp or mysql command prompt)

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

  3. open terminal.

  4. If you are using virtual environment then switch into it by using command ->workon env_name

  5. Now cd app_name eg. cd mysite

手順3,4,5は、アプリケーションでmanage.pyファイルが見つかったフォルダに到達する方法を示しています。

6.To check you are in right directory run command ls -l. If you find manage.py file then everything is right go ahead

7.python manage.py migrate

あなたは上記のコマンド実行中に「のMySQLdbという名前のモジュール」like-何らかのエラーがある場合は、あなたが行わ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 whatever you want to open Django admin site.

11.check you are having some tables in your database in localhost at ` http://localhost/phpmyadmin . You are good to go now.

関連する問題