add

MySql DB server installation

install mySql on Centos 7

MySQL

Introduction

This post will explain how to install MySQL ( Trademark of Oracle) on a CentOS 7 Opertaiong system.

MySql is an opensource relational Database management system that manages its data with SQL ( Structured query language).

Prerequisite to proceed with this installation is you should be a non-root user with sudo previlege on a centos & Box.

CentOS 7 comes with a mariaDB as a default package ( which is a fork of MySQL Database managed by MqSql community developers). Though you install the MySQL, it like mariaDb running in Background.

I would ask if you have specific requirement to use MySQL explicitly, its better to uninstall maria db ( though both can co-exist) with below command as i had many conflicts.

              yum remove MariaDB-server MariaDB-client

Make sure you dont have any leftovers of MariaDb related packages using rpm -qa | grep mariadb

if there are packages, you can remove them using:

rpm -e --nodeps "mariadb-libs-{version on ur box}"

Install MySQL

  1. Go to the community edition download page https://dev.mysql.com/downloads/mysql/ and select your appropriate operating system and OS type. I have chosen my preference as shown below. Click the RPM bundle which comes with all the dependency packages.


2. Verify the Md5sum by using command md5sum and compare with the md5 check sum on your download page.

$ md5sum mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar

b1fa36fc179f0988bf2357ed810f5ac5 mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar

3. Extract the contents of the downloaded rpm bundle.

Install the rpm packages in order : client, common-libs, common,devel , server using command : rpm -ivh <packagename>

Below are the list of RPM packages of MySql community edition ( reference: https://dev.mysql.com/doc/mysql-installation-excerpt/8.0/en/linux-installation-rpm.html)

Package NameSummary
mysql-community-clientMySQL client applications and tools
mysql-community-commonCommon files for server and client libraries
mysql-community-develDevelopment header files and libraries for MySQL database client applications
mysql-community-embedded-compatMySQL server as an embedded library with compatibility for applications using version 18 of the library
mysql-community-libsShared libraries for MySQL database client applications
mysql-community-libs-compatShared compatibility libraries for previous MySQL installations
mysql-community-serverDatabase server and related tools
mysql-community-server-debugDebug server and plugin binaries
mysql-community-testTest suite for the MySQL server
mysql-communityThe source code RPM looks similar to mysql-community-8.0.21-1.el7.src.rpm, depending on selected OS

4. MySQL is NOT automatically started at the end of the installation process. For Red Hat Enterprise Linux, Oracle Linux, CentOS, and Fedora systems, use the following command to start MySQL:

                    systemctl start mysqld

verify the status of the mqsqld daemon by running below command .

                    systemctl status mysqld

At the initial start up of the server, ideally the data directory of the server is empty and therefore an SSL certificate and key files are generated in the data directory.

Below are some of the important files/locations and their importance.

Files or ResourcesLocation
Client programs and scripts/usr/bin
mysqld server/usr/sbin
Configuration file/etc/my.cnf
Data directory/var/lib/mysql
Error log fileFor RHEL, Oracle Linux, CentOS or Fedora platforms: /var/log/mysqld.logFor SLES: /var/log/mysql/mysqld.log
Value of secure_file_priv/var/lib/mysql-files
System V init scriptFor RHEL, Oracle Linux, CentOS or Fedora platforms: /etc/init.d/mysqldFor SLES: /etc/init.d/mysql
Systemd serviceFor RHEL, Oracle Linux, CentOS or Fedora platforms: mysqldFor SLES: mysql
Pid file/var/run/mysql/mysqld.pid
Socket/var/lib/mysql/mysql.sock
Keyring directory/var/lib/mysql-keyring
Unix manual pages/usr/share/man
Include (header) files/usr/include/mysql
Libraries/usr/lib/mysql
Miscellaneous support files (for example, error messages, and character set files)/usr/share/mysql

The installation also creates a user named mysql and a group named mysql on the system.

After the installation process, a temporary password is generated for the MySQL root user. Locate it in the mysqld.log with this command:

Setting the Credentials to the MySQL server

MySQL comes up with a security script to change some of the default settings.

Use this command to run the security script.

sudo mysql_secure_installation

This prompt us for a default root password. provide the default password that we got from mysql log. It asks us to change it to the more

Output The existing password for the user account root has expired. Please set a new password.
New password: XXXXXXXX

Verify the MySQL server Installation

MySql server is shipped with a client mysqladmin to run the administration Verify the installation by folowing as below. this command collects the info and repsonds back to the screen.

You can install additional packages like My shell too which provides an interactive code execution mode, where you type code at the MySQL Shell prompt and each entered statement is processed, with the result of the processing printed onscreen:

                sudo yum install mysql-shell

Setting the MySQL Timezone

We can change the timezone either in MySql or configuration file /etc/mysql/my.cnf

For a Day to day purpose, you can use Dbeaver community edition which is one of the best tool available to interact with all SQL/NoSQL Databases.

Test Database : I downloaded a sample MySQL database from Source: https://www.mysqltutorial.org/mysql-sample-database.aspx

Import the data to MySql after extracting the zip file :mysqlsampledatabase.zip

Verify if all the databases are imported :

Written by Ramesh Metta