2012-04-16 25 views
12

Empecé a trabajar con django, y aquí está el error en 'runserver' después de la configuración 'BASES dE dATOS' en settings.pymysql_exceptions.OperationalError: (1045, "Acceso denegado para el usuario 'root' @ 'localhost' (usando la contraseña: YES)")

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

Mi parte settings.py de código:

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

} 

he creado la base de datos 'my_site' y privilegios se encuentran en el camino correcto (root tiene todos los privilegios) He realizado estas operaciones con 'phpmyadmin'.

¿Qué falla?

Respuesta

13

Ejecutar en la consola

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

realmente quiero ejecutar este comando a través de python. Pero tengo acceso denegado. ¿Alguna idea de cómo automatizar esto? Gracias –

0

su DB no reconoce su usuario y contraseña. Si puede ir a phpmyAdmin e intentar crear un usuario y una contraseña diferentes y asignarlos a la base de datos, si eso no funciona intente crear la consola pero crea con el usuario y otorgue todos.

+0

hecho: no funcionó –

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

leer en dev.mysql.com.

+0

no funciona para mí. –

0

Para cualquier persona que tiene este problema - asegúrese de que el usuario de la base anfitrión es localhost. Si se establece en %, no funcionará, deberá agregar localhost o cambiar la configuración general de seguridad.

3

Después de luchar por dos días finalmente encontré lo que está mal. pasos enteros para establecer una base de datos MySQL para Django sitio son-

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

Nota: -La contraseña y nombre de usuario dado anteriormente es de mi localhost usted tiene que cambiar a la suya.

  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

paso 3, 4 y 5 le indica cómo llegar a la carpeta donde se encuentra el archivo manage.py en su Aplicación.

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

Si tiene cualquier error como- "Sin módulo denominado MySQLdb" en el funcionamiento de comando anterior se puede visitar el 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.

Cuestiones relacionadas