How To Reset MySQL Password

on Tuesday, May 15, 2012
Sometimes, people forgot their password of MySQL. Then they confuse how to get back the root account on the MySQL Server. In this tutorial, we will show you step by step how to reset MySQL password.

First, you need to stop the MySQL service. Follow this command to stop the MySQL Service.
sudo service mysql stop
Next step is, you must start MySQL service again but with --skip-grant-tables option.
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &

Because you are not checking the privileges when start the MySQL Service. It is better for you to stop the Networking to prevent the security less action.

The next, login to the MySQL server using root account.
mysql -u root
After login with root account without password, please flush the privileges using this command
FLUSH PRIVILEGES;
Then, update your password
SET PASSWORD FOR root@'localhost' = PASSWORD('your password');
Then FLUSH PRIVILEGES again. Now, your password has been changed. Do not forget to restart your MySQL Service, with this command:
sudo service mysql restart

How To Create User and Database on MySQL

on Wednesday, October 26, 2011
Before you can create some user on MySQL, you have to login into MySQL with root/administrator account. The root account on MySQL is not belongs to root account on your system, but just on the MySQL. For login to MySQL root account, following this step:
[root@local ~]# mysql -h localhost -u root -p
Now, you can create another account into your MySQL with this command:
mysql> CREATE USER 'someuser'@'localhost' IDENTIFIED BY 'somepassword';
Please don't forget to use "localhost" when you create the account because if you forgot this, that means the account created could be connect from "%" or all host. We put the "localhost" for security reason, its mean only "localhost" can login into the MySQL with "someuser" username. After we made the user, then to make the database, we can use CREATE command:
mysql> CREATE DATABASE somedatabase;
Then, to grant access some user to the database, we use command GRANT.
mysql> FLUSH PRIVILEGES;
mysql> GRANT ALL PRIVILEGES ON somedatabase.* TO 'someuser'@'localhost' WITH GRANT OPTION;
To check the user have grant access to the database, you can use command SHOW:
mysql> SHOW GRANTS FOR someuser@localhost;

How To Install MySQL on CentOS

This article show you how to install MySQL on CentOS GNU/Linux with simple. To do this action, you must on root access. This tutorial can apply with all version of CentOS.
[root@local ~]# yum -y install mysql mysql-server
After you done above action, then continue with this action:
[root@local ~]# chkconfig --levels 235 mysqld on
Then, start MySQL daemon to run.
[root@local ~]# /etc/init.d/mysqld start
To make root password for MySQL, follow this step!
[root@local ~]# mysql_secure_installation
When the program try to request password, input your password for root on MySQL, BUT DO NOT your root's account password!. After that, you can connect to your MySQL server with this command:
[root@local ~]# mysql -u root -p
You are done now!