Howto Install MySQL on Linux

Most of the Linux distro comes with MySQL. If you want use MySQL, my recommendation is that you download the latest version of MySQL and install it yourself. Later you can upgrade it to the latest version when it becomes available. In this article, I will explain how to install the latest free community edition of MySQL on Linux platform.

1. Download the latest stable relase of MySQL

Download mySQL from mysql.com . Please download the community edition of MySQL for your appropriate Linux platform. I downloaded the “Red Hat Enterprise Linux 5 RPM (x86)”. Make sure to download MySQL Server, Client and “Headers and libraries” from the download page.

MySQL-client-community-5.1.25-0.rhel5.i386.rpm

MySQL-server-community-5.1.25-0.rhel5.i386.rpm

MySQL-devel-community-5.1.25-0.rhel5.i386.rpm

2. Remove the existing default MySQL that came with the Linux distro

Do not perform this on an system where the MySQL database is getting used by some application.

This will also display the following output and start the MySQL daemon automatically.

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h medica2 password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available at http://www.mysql.com/
Support MySQL by buying support/licenses from http://shop.mysql.com/
Starting MySQL.[ OK ]
Giving mysqld 2 seconds to start

Install the “Header and Libraries” that are part of the MySQL-devel packages.

Note: When I was compiling PHP with MySQL option from source on the Linux system, it failed with the following error. Installing the MySQL-devel-community package fixed this problem in installing PHP from source.

4. Perform post-install security activities on MySQL.

The best option is to run the mysql_secure_installation script that will take care of all the typical security related items on the MySQL as shown below. On a high level this does the following items:

Change the root password

Remove the anonymous user

Disallow root login from remote machines

Remove the default sample test database

[local-host]# /usr/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
You already have a root password set, so you can safely answer 'n'.
Change the root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y
... Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!

5. Verify the MySQL installation:

You can check the MySQL installed version by performing mysql -V as shown below:

Thank you so much for the detailed instructions. It would be helpful to add the expected exceptions and possible fixes too.
I had an issue with “Starting MySQL..Manager of pid-file quit without updating file.[Falure]”
I searched a lot in the internet and finally ended up at the solution.
starting “sudo /bin/sh /etc/init.d/mysql start” fixed the issue.
Hope this helps others who face the same issue on linux.

Hi,
Its good to see the MySQL 5x install procedure using RPMs. But I have a specific requirement to be implemented and I can’t see how to do that.
Instead of the default “mysql” user and group we need to create a client specific user who owns the mysql installation. How can I specify that, assuming that I create the user and group before starting installation with the RPM.

I have successfully installed mysql in my linux machine but can any one know , why after installing all the 3 rpms (client/server/devel) the version is reflected with “unknown -linux” instead of red-hat
rpm’s used for my installation below.

I am trying to install a software which required MySQL-server, MySQL-client installed on the server so now I want to install MySQL-server and MySQL-client using rpm files “MySQL-server-5.5.17-1.rhel5.x86_64.rpm” and “MySQL-client-5.5.17-1.rhel5.x86_64.rpm”.

in wndow 7 i install jomlla 1.5 in wamp server i change local host to ip address by now i am not able to open my page neither ip address nor local host anyone can help me.
—
hay i have red hat i want to install php my admin for my web server can u give me the installation manual step by step and what should be the other requirment pl give me manual i tried to install but i can not

Hello,
I installed mysql 5.6.11 (client and server) on my linux (Red Hat Linux 5). My issue is that the rpm installed everything on var/lib/mysql/dbname I want to install it under home/database/mysql/dbname.

how can I either move it to another spor, or if I uninstalle it, how do I go about installing it in the folder I want? Any help is greatly appreciated…thanks!!

Hello, Is it possible to install both 32bit and 64bit mysql on the same system and run them simultaneously? I have a linux system with 32bit Mysql installed. This is live and cannot be touched. I have a user that needs to import a database that is in excess of 30GB in size. I need to install a parallel installation of mysql in the 64bit version to handle the size of the database.

About The Geek Stuff

My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about Ramesh Natarajan and the blog.

Contact Us

Email Me :
Use this Contact Form to get in touch me with your comments, questions or suggestions about this site. You can also simply drop me a line to say hello!.