# mysql: access denied for root@localhost

## incubator

I have been trying to get mysql to work and I cant get any access.

When I type mysqladmin -u root -h localhost password '******' I get ERROR 1045: access denied for user: root@localhost

I ran mysql_install_db and then tried the above command, I changed the ownership of /var/lib/mysql/mysql to mysql.root

I manually edited the /etc/mysql/mysqlacces.conf

but to no avail

I am using apache2 and monmotha firewall, however I told it to allow port 3306 for mysql

----------

## Kirigoe

are you running the mysqladmin command with the -p switch? according to mysql_install_db you need to. and if you do and it asks for a password it should be blank.

 *Quote:*   

> 
> 
> PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
> 
> This is done with:
> ...

 

hope that helps[/quote]

----------

## incubator

did that, but wether I set a password or not, it keeps telling me the access  is denied

----------

## Souperman

How to reset MySQL root password

First stop mysqld:

```

root@wizard[pts/0]:/root# /etc/init.d/mysql stop

 * Stopping mysqld...                                                                         [ ok ]

```

Then start mysqld with the --skip-grant-tables option.  This makes it ignore access permissions specified in the 'mysql' database tables.  Note that this permits FULL ACCESS TO ANYONE and should thus not be run for very long.

```

root@wizard[pts/0]:/root# /usr/bin/mysqld_safe --skip-grant-tables &

[1] 27428

Starting mysqld daemon with databases from /var/lib/mysql

```

Now reset the MySQL root password.  Note that 'newpassword' specifies your new password as plaintext, the PASSWORD() function converts it into the crypted format:

```

root@wizard[pts/0]:/root# mysql -u root mysql

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3 to server version: 4.0.13-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> UPDATE user SET Password=PASSWORD('newpassword') WHERE User='root';

Query OK, 2 rows affected (0.00 sec)

Rows matched: 2  Changed: 2  Warnings: 0

mysql> quit

Bye

```

Now shut down mysqld.  Remember that you're running with --skip-grant tables, so you don't need to use a name or password.

```

root@wizard[pts/0]:/root# mysqladmin shutdown

031017 12:14:08  mysqld ended

```

Start mysqld again in normal mode:

```

root@wizard[pts/0]:/root# /etc/init.d/mysql start

 * Starting mysqld...                                                                         [ ok ]

```

Now you should be able to connect using your new root password:

```

root@wizard[pts/0]:/root# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1 to server version: 4.0.13-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

```

Hope this helps.   :Smile: 

----------

## incubator

thanks   :Very Happy: 

----------

## schmeggahead

I'm trying to access mysql remotely from another workstation using odbc (yea it's a wintel but there's a reason, there always is   :Surprised:  ) 

I setup a new mysql user (which is not a linux user) with access to my IP address and not localhost.

I have root working and another user id on localhost (which is also not a linux user)

Is there something I need to configure differently than give a user access to the IP address? I'm connecting using port 3306 in the ODBC setup and the reply on the wintel box is: 

```
[MySQL][ODBC 3.5.1 Driver] Can't connect to MySQL server on '192.168.0.109' (10061)
```

my host is 192.168.0.108

my database devtest exists (I've displayed from the PERSON table within it using another id)

my user is Erwin (defined in mysqladmin as Erwin@192.168.0.108)

correct password

port 3306 

and SQL command on connect is SELECT * FROM PERSON;

Any ideas?

----------

## Souperman

MySQL server listens on the loopback interface only by default, for security reasons.  If you look at /etc/mysql/my.cnf you see:

```

# keep secure by default!

bind-address    = 127.0.0.1

```

What you need to do is add your network IP to that so it'll listen on that interface as well, although I'm not sure how you do that.  You could try changing it to "127.0.0.1,192.168.0.109".

Whenever you change /etc/mysql/my.cnf you must restart mysqld:

```
# /etc/init.d/mysql restart
```

HTH

----------

## mrhodes

Souperman:  I tried what you said exactly as you said to, and there were no errors until the very end when I tried to login... still same problem, says 

"ERROR 1045: Access denied for user: 'root@localhost' (Using password: YES)"

Anyone have any ideas how I can completely reset this, without reinstalling gentoo...

Thanks,

----------

## Souperman

 *mrhodes wrote:*   

> Souperman:  I tried what you said exactly as you said to, and there were no errors until the very end when I tried to login... still same problem, says 
> 
> "ERROR 1045: Access denied for user: 'root@localhost' (Using password: YES)"
> 
> Anyone have any ideas how I can completely reset this, without reinstalling gentoo...
> ...

 

When you reset the password did mysql indicate that it had updated one or more rows?  Example:

```

mysql> UPDATE user SET Password=PASSWORD('newpassword') WHERE User='root'; 

Query OK, 2 rows affected (0.00 sec) 

Rows matched: 2  Changed: 2  Warnings: 0 
```

If not, then do it again.  If it did ..... well not sure what the problem may be to be perfectly honest ... perhaps you mistyped the new password when you reset it or when you tried to login?

----------

## mrhodes

Yes, it said that one row has been updated.

I don't know what the problem is, this is a strange one.   I would really like to get it working because I want to use it with php on my website....

hopefully something will come up...

Thanks for all your help guys  :Smile:    Problem is still open if anyone has ideas...

----------

## Kenja

hmm I've reviewed this post in search of fixing my problem with MySQL

```
mysql> UPDATE user SET Password=PASSWORD('newpassword') WHERE User='root'; 

Query OK, 2 rows affected (0.00 sec) 

Rows matched: 2  Changed: 2  Warnings: 0 
```

The syntax here confuses me.

Which are variables (ie., my password and/or user name ) and which are to be entered verbatim?

----------

## Kenja

bump

----------

## Dr_Stein

Same issue has now stung me. I can reset the password, but am then totally unable to log in -  

jimihendrix jnichols # mysql -uroot -p

Enter password: 

ERROR 1045: Access denied for user: 'root@localhost' (Using password: YES)

jimihendrix jnichols # 

The only thing I did was update MySQL from portage. 4.0.17 to 4.0.18...

----------

