1
import MySQLdb
db = MySQLdb.connect("localhost","root","root","aditya")
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print(data)
db.close()

result:

Traceback (most recent call last):
  File "C:\Users\Aditya\Desktop\database.py", line 4, in <module>
    db = MySQLdb.connect("localhost","root","root","aditya")
  File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")

this is pretty basic stuff ? i am not able to understand where am i going wrong. i am using python 2.7 , mySQL version 5.6 , OS: windows 10

mysql> show grants for 'root'@'localhost';
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION


mysql> select * from mysql.user where user='root'\G
*************************** 1. row ***************************
                  Host: localhost
                  User: root
              Password: *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B
           Select_priv: Y
           Insert_priv: Y
           Update_priv: Y
           Delete_priv: Y
           Create_priv: Y
             Drop_priv: Y
           Reload_priv: Y
         Shutdown_priv: Y
          Process_priv: Y
             File_priv: Y
            Grant_priv: Y
       References_priv: Y
            Index_priv: Y
            Alter_priv: Y
          Show_db_priv: Y
            Super_priv: Y
 Create_tmp_table_priv: Y
      Lock_tables_priv: Y
          Execute_priv: Y
       Repl_slave_priv: Y
      Repl_client_priv: Y
      Create_view_priv: Y
        Show_view_priv: Y
   Create_routine_priv: Y
    Alter_routine_priv: Y
      Create_user_priv: Y
            Event_priv: Y
          Trigger_priv: Y
Create_tablespace_priv: Y
              ssl_type:
            ssl_cipher:
           x509_issuer:
          x509_subject:
         max_questions: 0
           max_updates: 0
       max_connections: 0
  max_user_connections: 0
                plugin: mysql_native_password
 authentication_string:
      password_expired: N

i am having all the privileges to access the database. its working perfectly in MySQL command line client.

aditya mathur
  • 75
  • 1
  • 2
  • 6
  • Possible duplicate of [Access denied for user 'root'@'localhost' while attempting to grant privileges. How do I grant privileges?](http://stackoverflow.com/questions/8484722/access-denied-for-user-rootlocalhost-while-attempting-to-grant-privileges) – tlastowka Oct 11 '15 at 18:58
  • Try the solution in this answer: http://stackoverflow.com/a/489502/2104879 – mertyildiran Oct 11 '15 at 19:20
  • i tried what was mentioned for this question, still it didn't worked for me. – aditya mathur Oct 11 '15 at 19:20

1 Answers1

0

Can you connect using the MySQL command line tool with the same credentials?

Jon Farmer
  • 326
  • 1
  • 6
  • 16