Ady Wicaksono Daily Activities

Forget mysql root password

leave a comment »

Yeah, just now my client contacted me over email, seems there’s a bug on my application
so I need to fix it, it’s Linux + Apache + MySQL + PHP (LAMP). I promised him to fix soon
(because we live in different timezone, he’s in Canada and I’m here at Singapore and I was on bad mood by that time)

Huh, I forget the mysql password…. and he must be sleeping now, so I can’t ask him,
So what’s the solution, because I need to access mysql….
Here what I did (the same with MySQL manual hehehe…):

1. Shutdown mysql first
# /etc/rc.d/init.d/mysqld stop
Stopping MySQL:                                            [  OK  ]

2. Run mysql server with option --skip-grant-tables --user=root 
   (run in background mode please)

# /usr/bin/mysqld_safe --skip-grant-tables --user=root  &
Starting mysqld daemon with databases from /var/lib/mysql

3. Connect to mysql using mysql client and execute these SQL statements below:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.20

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

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

4. Restart MySQL (this step is optional)

# /etc/rc.d/init.d/mysqld restart
STOPPING server from pid file /var/run/mysqld/
080223 08:07:23  mysqld ended
Stopping MySQL:                                            [  OK  ]
Starting MySQL:                                            [  OK  ]

5. Now our root MySQL server has password 'newpwd'

Written by adywicaksono

February 23, 2008 at 3:09 pm

Posted in, MySQL

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: