How to install MySQL server and client on Linux

MySQL is the most popular open-source database management system supporting transactional relational databases. MySQL runs in a server-client architecture, where a MySQL server manages persistent databases and provides SQL query interfaces, while MySQL clients query the MySQL server to access MySQL databases.

In this tutorial, I will describe how to install MySQL server and client on Linux, by using a given distro's default package manager.

Install MySQL Server in Linux

To install MySQL server in Ubuntu or Debian:

$ sudo apt-get install mysql-server

During installation, you will be asked to provide the initial root password of the MySQL server. Once installation is completed, MySQL server gets started immediately, and is set to start automatically upon boot.

To install and auto-start MySQL server on boot in CentOS or RHEL:

$ sudo yum groupinstall "MySQL Database server"
$ sudo chkconfig mysqld on

To install and auto-start MySQL server on boot in Fedora:

$ sudo yum install mysql-server
$ sudo systemctl enable mysqld.service

On CentOS, Fedora or RHEL, the default installation of MySQL has no root password set, which means that anyone can log in to the root without entering any password. Thus, make sure to set the root password after installation. To set the root password, first install MySQL client (explained below), and run the following command.

$ mysqladmin -u root password 'newpass' (in case the current password is empty)
$ mysqladmin -u root -p'oldpass' password 'newpass' (in case the current password is not empty)

Install MySQL Client in Linux

To install MySQL client in Ubuntu or Debian:

$ sudo apt-get install mysql-client

To install MySQL client in CentOS or RHEL:

$ sudo yum groupinstall "MySQL Database client"

To install MySQL client in Fedora:

$ sudo yum install mysql

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Leave a comment

Your email address will not be published. Required fields are marked *

Current day month ye@r *