2012-04-16 12 views
12

मैंने django के साथ काम करना शुरू कर दिया है, और यहां सेट करने के बाद' रनरवर 'पर त्रुटि है settings.py में 'डेटाबेस'mysql_exceptions.OperationalError: (1045, "उपयोगकर्ता के रूट '@' लोकहोस्ट '(पासवर्ड का उपयोग करके: एचईएस) के लिए प्रवेश अस्वीकार")

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

सांत्वना

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

मैं वास्तव में पाइथन के माध्यम से यह आदेश चलाने के लिए चाहता हूँ। लेकिन मुझे पहुंच से वंचित कर दिया गया। कोई विचार यह कैसे स्वचालित करें? धन्यवाद –

0

आपका डीबी आपके रूट उपयोगकर्ता और पासवर्ड को पहचान नहीं करता है। यदि आप phpmyAdmin पर जा सकते हैं और एक अलग उपयोगकर्ता और पासवर्ड बनाने की कोशिश कर सकते हैं और डीबी को असाइन कर सकते हैं, यदि यह काम नहीं कर रहा है तो बनाने के लिए प्रयास करें लेकिन उपयोगकर्ता बनाने के साथ कंसोल करें, और सभी को दें।

+0

किया में जैसे "नहीं मॉड्यूल MySQLdb नाम" किसी भी त्रुटि हो रही है: –

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'???

रूप dev.mysql.com पर पढ़ें।

+0

काम नहीं किया मेरे लिए काम नहीं करता। –

0

में चलाएँ इस समस्या का सामना किसी के लिए - यह सुनिश्चित करें कि डेटाबेस उपयोगकर्ता मेजबानlocalhost है बनाने के लिए जाँच करें। यदि % पर सेट किया गया है, तो यह काम नहीं करेगा, आपको localhost जोड़ने या अपनी समग्र सुरक्षा सेटिंग्स बदलने की आवश्यकता होगी।

3

दो दिनों के लिए संघर्ष करने के बाद मुझे अंत में क्या गलत लगता है। पूरे Django साइट के लिए एक mysql डेटाबेस सेटअप करने के चरण हैं-

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': '', 
    } } 

नोट: -इस पासवर्ड और उपयोगकर्ता नाम ऊपर दिए गए मेरे स्थानीय होस्ट तुम अपने लिए इसे बदल दिया है की है।

  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

आप कमांड ऊपर चल रहा है आप यात्रा कर सकते हैं 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.

संबंधित मुद्दे

 संबंधित मुद्दे