# Mysql won't let me set a password for root user

## Delkaton

Argh, mysql is giving me problems again. I formated my computer and had to install it again. So I emerged mysql and tried to set a password for it. Here's what I got:

```

bash-2.05b$ /usr/bin/mysqladmin -u root -h localhost password 'Hi98TeR'

/usr/bin/mysqladmin: unable to change password; error: 'Access denied for user: '@localhost' to database 'mysql''

bash-2.05b$ mysql

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

Your MySQL connection id is 5 to server version: 4.0.18

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

mysql> use mysql

ERROR 1044: Access denied for user: '@localhost' to database 'mysql'

mysql> \q

Bye

bash-2.05b$ mysql -u root -p

Enter password: 

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

bash-2.05b$ mysql -u root -p

Enter password: 

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

Your MySQL connection id is 7 to server version: 4.0.18

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

mysql> 

```

As you can see, it won't let me set a password if I try. If I type only mysql, it will enter mysql console. If I try the same using any password I am blocked. If I try to access mysql tables I get permission denied. And for some reason, mysql seems to not recognize a user, but only the host (@localhost).

----------

## adaptr

Yes - have you run the database setup script after installation ?

This creates the initial entries in the mysql tables.

----------

## Delkaton

Yes I did.

----------

## Danathan

while the '@localhost' thing seems bizarre to me, the rest of it seems consistent with just being wrong as to what your root password is.  the procedure for reseting a lost mysql root password is here:

http://www.mysql.com/documentation/mysql/bychapter/manual_Problems.html#Resetting_permissions

maybe that'll help.[/url]

----------

## zeky

My advice to you to install webmin or phpmyadmin and configure your MySQL users from there, it's much more user-friendly than plain console. And it works like a charm.

----------

## Danathan

 *Quote:*   

> 
> 
> bash-2.05b$ mysql -u root -p
> 
> Enter password:
> ...

 

That looks like you successfully logged in as root... so disregard my last post.  I guess I'm confused as what the problem you're having is.  If it's changing the root password, you'll need to supply the current root password, so the command looks like:

```

mysqladmin -u root -p password 'newpass'

```

Hope this helps.[/quote]

----------

## Delkaton

Problem is, I never got tthe chance to set a password. The first time I tried to do it, I got access denied. I can get into mysql prompt but it won't let me do nothing else. It is as if mysql had already chosen a password for me, and I can't discover which one it is.

----------

## MajikC

I have had this problem before and again, I can set the password for external use, i.e.

mysqladmin -u root -h myhostname.net password "newpassword"

but when I try it for localhost using;

mysqladmin -u root password "newpassword"

I recieve the same error as yourself. The link on this page though fixed it for myself. So I  recomend try it, kill your mysql server restart it in safe mode and then change the password, thats the second load of intstructions at this link, which is provided above by Danathan. Everything you are doing looks right to me and it probably is just that the mysql database already has a password, but even the root password isnt working for me. So thanks Danathan for finding a solution (if not yet the cause) of this problem   :Very Happy: 

http://www.mysql.com/documentation/mysql/bychapter/manual_Problems.html#Resetting_permissions

----------

## Delkaton

Ok, here's my problem. This are the mysql processes that are runing

```

24137 ?        S      0:00  \_ /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-locking --port=3306

24138 ?        S      0:00      \_ /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-locking --port=

24139 ?        S      0:00          \_ /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-locking --p

24140 ?        S      0:00          \_ /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-locking --p

bash-2.05b# 

```

Sorry, my screen is not wide enough to get it entirely. The thing is when I try to 

```

kill `cat /mysql-data-directory/hostname.pid`

```

I can't get it to work. I tried a lot of diferent ways but I can never get it right. So I killed it using:

```

killall mysqld

```

And them I tried to 

```

mysqld_safe --skip-grant-tables &

```

But nothing happened.  Mysql just sit there trying to start. So I tried using the next command:

```

 mysqladmin -u root flush-privileges password "newpwd"

mysqladmin: reload failed; error: 'Access denied. You need the RELOAD privilege for this operation'

```

Anyway I tried to get mysql to work, and it did. It was working fine. But when I closed the terminal where I had typed the mysqld_safe, mysql stopped working. Now what?

----------

## flavio

Just become root in your box (log in as root or just use "su -") and try to set the password again. It will work this time.

----------

## Delkaton

I was root when I tried this.

----------

## flavio

It was not reflected in the previous posts as your system prompt was a $... Are you sure that you were root when you run the command: mysql? Usually the sequence of things that you need to do if mysqladmin doesn't work properly is:

1) log in as root in your system

2) Run "mysql"

3) Type "use mysql;"

4) Type "update user set password=password("yourpassword") where user like "root;"

5) Type "flush privileges;"

----------

## Delkaton

Ok, I tried again and this is what I got:

```

Tyfon root # mysqladmin -u root flush-privileges password "blah123"

mysqladmin: unable to change password; error: 'Can't find any matching row in the user table'

```

----------

## weisrc

Delkaton,

Any fix for this? I'm in the same boat...been fighting MYSQL to set a root pw and get this up and running. Not sure wtf I'm doing wrong. 

Any ideas?

----------

## Delkaton

No, I am still stuck here. I managed to make it work temporaly by running it with the

```
 mysqld_safe --skip-grant tables &
```

command, but I don't have to tell you that this is not safe...

----------

## Danathan

It sounds like there's no entry for root in the users table.    :Shocked: 

After you've loaded without grant tables, you can drop down into a mysql shell, yes?  If so, use mysql and then

SELECT User, Host FROM user;

and see what you've got... if you don't have a root | localhost, that would probably be the source of your problems.

Dan

----------

## weisrc

I decided to use brute force and ignorance to fix this.

I unmerged all my apache, php, mysql then downloaded XAMPP from

http://www.apachefriends.org/index-en.html

Heres what I did to get XAMPP running:

1) Download their tar file

2) UnTarred using this command:

```
tar xvfz xampp-linux-1.4.3.tar.gz -C /opt
```

Next, I didn't follow their step #2 since it didn't work. The command acted like it didn't exist...Not sure why...I'm too much of a noobie to figure that out.

SO, what I did was loaded it on startup by doing this:

Modify: /etc/conf.d/local.start 

and add the following line at the bottom:

```
/opt/lampp/lampp start
```

If this causes security or other problems, I have no clue. But, it loaded up my XAMPP successfull on boot and got MYSQL working, PHP, Apache, and a lot of other stuff. 

Enjoy!

----------

## Delkaton

IT WORKED!!!!!

This is what I get after runing the command

```

mysql> USE mysql

Reading table information for completion of table and column names

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

Database changed

mysql> SELECT User, Host FROM user;

+------+-----------+

| User | Host      |

+------+-----------+

|      | localhost |

| root | localhost |

+------+-----------+

2 rows in set (0.00 sec)

mysql> 

```

After that I tried reseting the permission and it worked. Strangely, it wasn't working before. Well, thanks a lot for the patiece and help guy.

----------

