Introduction
MySQL is an open source relational database management system (RDBMS) with a client-server architecture. RDBMS is a software or service used to create and manage databases based on a relational model.
This guide will show you how to install MySQL Server (Community Edition) using the default package manager on CentOS/RHEL 7/6, Fedora 31/30/29.
Step 1: Yum Repository Configuration
### On CentOS/RHEL 7 system ###
rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
-------------------------------------------
### On CentOS/RHEL 6 system ###
rpm -Uvh https://repo.mysql.com/mysql80-community-release-el6-3.noarch.rpm
-------------------------------------------
### On Fedora 32 system ###
rpm -Uvh https://repo.mysql.com/mysql80-community-release-fc32-1.noarch.rpm
-------------------------------------------
### On Fedora 31 system ###
rpm -Uvh https://repo.mysql.com/mysql80-community-release-fc31-1.noarch.rpm
-------------------------------------------
### On Fedora 30 system ###
rpm -Uvh https://repo.mysql.com/mysql80-community-release-fc30-1.noarch.rpm
Step 2: Install MySQL Community Server
MySQL yum includes numerous repository configurations for various MySQL versions.
So, in the MySQL repo file, first deactivate all repositories.
$ sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/mysql-community.repo
Then, depending on your operating system, use one of the following instructions to install MySQL.
CentOS & Red Hat
$ yum --enablerepo=mysql57-community install mysql-community-server
Fedora Systems
$ dnf --enablerepo=mysql57-community install mysql-community-server
Step 3: Start MySQL Service
To start the MySQL server, we can use services or systemctl command
Using SysVinit
$ service mysqld start
Using Systemd
$ systemctl start mysqld.service
Step 4: Find MySQL root Password
During the installation of MySQL 5.7, a temporary password for the user root MySQL is created. The temporary password generated can be found in the log files.
$ grep "A temporary password" /var/log/mysqld.log
Output :
[Note] A temporary password is generated for root@server: Hsb65pdh@t1a6
Step 5: MySQL Post Install Setup
Run the MySQL secure installation command mysql_secure_installation to secure the MySQL server after the initial installation. We recommend saying “yes” (y) to each of the questions it will ask.
$ mysql_secure_installation
Output :
Enter password for user root: The existing password for the user account root has expired. Please set a new password. New password: Re-enter new password: The 'validate_password' plugin is installed on the server. The subsequent steps will run with the existing configuration of the plugin. Using existing password for root. Estimated strength of the password: 100 Change the password for root ? y 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 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 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 — 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 Success. All done!
Step 6: Restart and Enable MySQL Service
Once you’ve done installing MySQL and configuring the basic options, restart the MySQL service using the following command.
Using SysVinit
$ service mysqld restart
Using Systemd
$ systemctl restart mysqld.service
Moreover, use the following command to enable automatic service startup upon system boot.
### Using SysVinit
chkconfig mysqld on
### Using Systemd
systemctl enable mysqld.service
Step 7: Working with MySQL
Now let’s connect to the MySQL database server, type the new password when prompted
let’s run some SQL statements.
### CREATE DATABASE mysql> CREATE DATABASE DBTest; ### CREATE USER ACCOUNT mysql> CREATE USER 'dbtestuser'@'192.168.10.101' IDENTIFIED BY 'secretPass'; ### GRANT PERMISSIONS ON DATABASE mysql> GRANT ALL ON DBTest.* TO 'dbtestuser'@'192.168.1.100'; ### RELOAD PRIVILEGES mysql> FLUSH PRIVILEGES;
Congratulations! MySQL server has been successfully installed on your machine.