# setting mysql password problems

## stingray72

after emerging mysql and running the ebuild config that it told me to and starting the server, I tried to set the password for root with

```
/usr/bin/mysqladmin -u root password 'new-password'
```

but when I tried to run mysql as root and entered my password I got "access denied for root@localhost"

Funny thing is, I can run mysql as my normal user without a password, but when I tried to set the password, same format as above except -u username I got an error that looked like

Access denied for user '@localhost' like it wasn't seeing my username or something.  Could anyone give me some insight into this??

Thanks in advance...

----------

## fyerk

You need to reload the grant tables after making a password change.

```

# mysqladmin flush-privileges

```

----------

## stingray72

hmmm, I guess I missed that in the mysql docs.  Thanks edge, I'll try it when I get home

----------

## stingray72

OK, that didn't work b/c I'm still getting access denied for user root@localhost.  I'd like to start this whole process over.  Is there a way to re-emerge mysql and then reconfigure it?  I unmerged it then emerged it again but when I did the ebuild - config part it thought that the database had already been configured.  I'd like to start all over again if I could.

----------

## rac

unmerge it and then rm /var/lib/mysql.  That ought to get rid of everything.

----------

## n0n

What's the exact command line you're using to try to get into mysql as root?  Be sure you've got the "-p" in the options, I've been caught by that a few times.

----------

## stingray72

Well I tried setting the password with

```
mysqladmin -u root -p 'oldpassword' password 'newpassword'
```

when that worked I tried

```
mysql -u root -p 'password'
```

it then prompts me to "Enter Password:" again and I can never get access

----------

## n0n

 *stingray72 wrote:*   

> 
> 
> ```
> mysql -u root -p 'password'
> ```
> ...

 

If you're going to enter the password on the command line, you've got to either use the long form (--password=blah) or get rid of the space after -p (-pblah).  The reason being is that ordinarily you don't want to specify the password on the command line if you can at all help it, as it's insecure in a staggering number of ways.  The "-p" option by itself tells mysql, "ask me for the password interactively."

Just try "mysql -u root -p" and then type in your password when prompted; it'll probably work much better.

----------

## stingray72

OK, obviously my hostname is FUBAR somehow.  I can access anything with root@gentoo but not root@localhost

```
mysql -u root@gentoo
```

works but

```
mysql -u root
```

does not.

What gives?

The user is still not created though...

----------

## n0n

If you can get in at all, "use mysql" and then "select * from user".  You'll notice that users are actually stored with a "user" value and a "host" value, and the password for a user coming in via one host can be different from if that user comes in from a different host.  If "user@gentoo" works, but just "user" doesn't (likely defaults to "user@localhost"), then it's likely that only the entry under BOTH "user" and "gentoo" was updated, as opposed to the main one.

----------

## stingray72

Hey guys, I got it working.  I unmerged it, deleted /var/lib/mysql like rac suggested and then installed the database exactly like mysql.com suggested instead of the ebuild scripts suggestions.  I'm pretty sure it was user errer b/c obviously I couldn't get the mysqladmin options correct.  Anyway, updating the mysql database manually was the way to go.

Thanks n0n and others

----------

