Custom Search
Showing posts with label configure mysql. Show all posts
Showing posts with label configure mysql. Show all posts

Ubuntu mysql reset root password

Perhaps you provided the wrong password? Don't worry, you can reset Ubuntu mysql root password, here's how to do it:

If mysql is running, then you have to stop it first. If you not sure, we can check Ubuntu running services with ps command to check mysql service is there or not.


luzar@ubuntu:~$ ps aux | grep mysqld
root 4078 0.0 0.1 1772 524 ? S 05:19 0:00 /bin/sh /usr/bin/mysqld_safe
mysql 4120 0.0 3.1 127088 16312 ? Sl 05:19 0:02 /usr/sbin/mysqld --basedir
root 4122 0.0 0.1 1700 556 ? S 05:19 0:00 logger -p daemon.err -t
luzar 4885 0.0 0.1 3004 752 pts/0 R+ 09:50 0:00 grep mysqld


If you see mysql service like in the example above, then you need to stop it. All you need from the ps command above is the process id. Look closely at mysql service, and write down that number. Then you can issue the command below:


luzar@ubuntu:~$ sudo kill 4120
luzar@ubuntu:~$ ps aux | grep mysqld
luzar 4891 0.0 0.1 3004 752 pts/0 R+ 09:50 0:00 grep mysqld
luzar@ubuntu:~$


We can use the same ps command as before to check that mysql really died. So there is no more mysql service.

There are two ways to reset mysql root password. The first way is by putting a script of mysql command to reset root password in a file. Then run mysqld_safe command with the file.

The second way is by running mysql directly from the shell.

Here is a step by step example of resetting mysql root password with a file:

1) Create a text file in your home directory named mysql-passwd with the content below:


UPDATE mysql.user SET Password=PASSWORD('Password') WHERE User='root';
FLUSH PRIVILEGES;


2) Now you can start mysql with the mysql password file to reset Ubuntu mysql root password. Follow the syntax below but change the password name to yours.


luzar@ubuntu:~$ mysqld_safe --init-file=/home/me/mysql-passwd &


3)After the mysql server successfully started, delete the root password file you in your home directory.

4)You can now login mysql using your new password.

Ubuntu mysql root password

This is a guide on how to set Ubuntu mysql root password. Mysql root password is not the same as Linux root password. They do not share the same account. Mysql has its own root user.

If you didn't choose to install mysql during Ubuntu installation setup, you can install it now. It's just two simple steps. Check my previous post, Ubuntu mysql install guide.

You can use the command below to set mysql root password:

luzar@ubuntu:~$ sudo mysqladmin -u root password new_password

You need to restart the mysql server then:

luzar@ubuntu:~$ sudo /etc/init.d/mysql restart

Ubuntu mysql install

You can check whether mysql has been installed in Ubuntu system with the ps command or dpkg command to check the installed package.

Check mysql daemon using ps command:


luzar@ubuntu:~$ ps aux | grep mysql
root 4078 0.0 0.1 1772 524 ? S 05:19 0:00 /bin/sh /usr/bin/mysqld_safe
mysql 4120 0.0 3.1 127088 16312 ? Sl 05:19 0:01 /usr/sbin/mysqld
--basedir=/usr --datadir=/var/lib/mysql --user=mysql
--pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking
--port=3306 --socket=/var/run/mysqld/mysqld.sock
root 4122 0.0 0.1 1700 556 ? S 05:19 0:00 logger -p
daemon.err -t mysqld_safe -i -t mysqld
luzar 4775 0.0 0.1 3004 752 pts/0 R+ 07:51 0:00 grep mysql
luzar@ubuntu:~$


Check mysql package using dpkg command:


luzar@ubuntu:~$ dpkg -l | grep mysql
ii libdbd-mysql-perl 4.005-1 A Perl5 database interface to the
MySQL data
ii libmysqlclient15off 5.0.51a-3ubuntu5.1 MySQL database client library
ii mysql-client-5.0 5.0.51a-3ubuntu5.1 MySQL database client binaries
ii mysql-common 5.0.51a-3ubuntu5.1 MySQL database common files
ii mysql-server 5.0.51a-3ubuntu5.1 MySQL database server
(meta package dependin
ii mysql-server-5.0 5.0.51a-3ubuntu5.1 MySQL database server binaries
ii php5-mysql 5.2.4-2ubuntu5.1 MySQL module for php5
luzar@ubuntu:~$


So I already have mysql installed during installation. If you don't have mysql in your Ubuntu server, you can install it using apt-get command. If you already configured your Internet connection, then issue the apt-get command like in the example below:


luzar@ubuntu:~$ apt-get install mysql-server-5.0


The apt-get tool will ask you to confirm the mysql installation, and you need to answer Y (yes).

That's all you need to do to have mysql installed in your Ubuntu system.