Reset Mysql's root password.
Uh ohh... I forgetten Mysql's root password! Since I cant access the grant tables, how do I reset it? If you find yourself asking this question, there are a few easy steps to take, and you'll be back up in no time. First, you will want to halt your mysql server.
service mysqld stop Stopping MySQL: [ OK ]
Next, you will want to edit your /etc/my.cnf, and add "skip-grant-tables" to the [mysqld] section.
This will make mysql startup without any passwords, allowing you to login as root.
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Default to using old password format for compatibility with mysql 3.x # clients (those using the mysqlclient10 compatibility package). old_passwords=1 skip-grant-tables [mysql.server] user=mysql basedir=/var/lib [mysqld_safe] err-log=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
Next, restart mysql.
service mysqld start Starting MySQL: [ OK ]
Now, go ahead and login to mysql.
mysql 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 2 to server version: 4.1.20 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql>
We can now assign a password to root.
update mysql.user set password=PASSWORD('$mypass123') where user='root';
flush privileges;
Now edit /etc/my.cnf, and comment out skip-grant-tables, and restart mysql.
service mysqld restart Stopping MySQL: [ OK ] Starting MySQL: [ OK ]
Now, connect to mysql as root, with your new password.
mysql mysql -u root -p Enter password: ........ 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 2 to server version: 4.1.20 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql>
Now, you can assign permissions to your various tables using the grant statements.
grant all on $mydb.* to $myuser@localhost identified by '$mypassword'; grant all on $mydb.* to $myuser@'www.myhost.com' identified by '$mypassword'; grant all on $mydb.* to $myuser@'1.2.3.4' identified by '$mypassword'; flush privileges;
- Login to post comments
