-1

why we need --skip-grant-tables to remove Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) Every where either for linux/unix or windows there is same error. can any one please explain it. And what does --skip-grant-tables really do? here is my code

import MySQLdb
db=MySQLdb.connect(host="localhost",
                   user="root",
                   passwd="********",
                   db="test")
Kushagra Sharma
  • 101
  • 1
  • 11

3 Answers3

2

Straight from the MySQL Docs:

This option causes the server to start without using the privilege system at all, which gives anyone with access to the server unrestricted access to all databases. You can cause a running server to start using the grant tables again by executing mysqladmin flush-privileges or mysqladmin reload command from a system shell, or by issuing a MySQL FLUSH PRIVILEGES statement after connecting to the server. This option also suppresses loading of user-defined functions (UDFs).

Basically, this removes the Access Denied error by not checking the password, which is useful in a few cases (basically when instructed by the docs), such as when you are resetting your root password. However, this is not a solution to an Access Denied error. That would be like taking the lock off your door after discovering your house key doesn't work!

Two-Bit Alchemist
  • 17,966
  • 6
  • 47
  • 82
  • why should we use it ,when we know our root password? why our root password doesn't work here?? – Kushagra Sharma Apr 03 '14 at 21:41
  • Why we can't connect with our username, what is the need of username and passwd if it never work for me? Then what is the power of root here. – Kushagra Sharma Apr 03 '14 at 21:45
  • Re-read my last sentence, as that still seems to be your mentality. You say you know your root password, but the computer (MySQL) says you don't. Time to figure out what the discrepancy is! – Two-Bit Alchemist Apr 03 '14 at 21:51
  • but when I open it using workbench , my root passwd works properly. – Kushagra Sharma Apr 03 '14 at 21:54
  • Does [this question and answer](http://dba.stackexchange.com/questions/44114/cant-connect-to-a-mysql-from-the-command-line-works-from-mysql-workbench) help? – Two-Bit Alchemist Apr 03 '14 at 21:59
  • One more thing When I use >mysql -u root(or any username) it works properly ,it connect with mysql and doesn't ask for passwd (why this happen??) but when i use >mysql -u root -p That's why i am confuse with mysql. it never work for me. – Kushagra Sharma Apr 03 '14 at 21:59
  • I don't think you are actually logging on as `root` in that case. I think it is letting you in on the default guest account (which has no password). Check the answer I linked to see what user you really are. – Two-Bit Alchemist Apr 03 '14 at 22:05
  • NO that question doesn't help me , because i know that thing. When i use **mysql5.7 command line client unicode** in windows, all works fine but when i try it using cmd(by setting path ) ,it doesn't work. while in unix/linux it never work for me untill i use --skip-grant tables – Kushagra Sharma Apr 03 '14 at 22:10
  • I don't know Windows or MySQL workbench because I use Linux and the command line. You say you can log in as `mysql -u [any string]` but not with `-p` which asks you for password (which it says is wrong). You say you are not asked for a password. That suggests to me you are getting logged in as `guest` (no password), but I can't do anything else if you won't check that. – Two-Bit Alchemist Apr 03 '14 at 22:13
  • yaa i tried it , it says GRANT ALL PRIVILEGE ON *.* TO 'root@localhost' – Kushagra Sharma Apr 03 '14 at 22:14
0

I think now i got it, here error is Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) so i just change my code as :

import MySQLdb
db=MySQLdb.connect("localhost","root",'',"test")

OR

import MySQLdb
db=MySQLdb.connect(host="localhost",
                   user="root",
                   passwd='',
                   db="test")

Here i set NULL password as error is Access denied for user using password yes

Now if anybody has any ques related to it please discuss ...thanks

Kushagra Sharma
  • 101
  • 1
  • 11
0

There must be conflict between your mysql password and password you uses in your application. You should not use --skip-grant-tables options as it will start your server without using the privilege system. It must be dangerous for you. Any one can access your account if you will use it.