How to install MySQL server and client on Linux

Last updated on November 28, 2020 by Dan Nanni

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

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.

Install and auto-start MySQL server on boot in CentOS or RHEL

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

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)

Create a MySQL User

After MySQL server installation, it is strongly recommend that you create a MySQL user account with appropriate access privileges (instead of logging in as root).

Install MySQL Client in Linux

Install MySQL client in Ubuntu or Debian

$ sudo apt-get install mysql-client

Install MySQL client in CentOS or RHEL

$ sudo yum groupinstall "MySQL Database client"

Install MySQL client in Fedora

$ sudo yum install mysql

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean