How to install MySQL server on CentOS 8 Linux
How we can install MySQL Server 8 on Centos8 Machine, we further will see how we can create and work on an Database on same.
Oracle MySQL Server 8 is free OpenSource database which is famous among users who like to use OpenSource database, So it also important part of LAMP(Linux,nix/Apache,Nginx/MySQL/Perl,Python). There are various OpenSource platform like WordPress. In this post we will see how we can install MySQL on CentOS8.
SetUP
During this setup, we are using CentOS8 as mentioned below
# [root@srv19 ~]# lsb_release -a LSB Version: :core-4.1-amd64:core-4.1-noarch Distributor ID: CentOS Description: CentOS Linux release 8.3.2011 Release: 8.3.2011 Codename: n/a #Redhat Release file [root@srv19 ~]# cat /etc/redhat-release CentOS Linux release 8.3.2011 #Kernel Details [root@srv19 ~]# uname -r 4.18.0-193.28.1.el8_2.x86_64
We have latest CentOS8 machine , we just update it with below command before installation of MySQL on this machine
# yum update
Installation of MySQL
let’s install MySQL Server 8 on CentOS. For installation of MySQL8 Server, we used yum command like below.
#yum install mysql-server
This will ask to press Yes and further install packages on same machine.We can see package information with below command.
[root@srv19 ~]# /usr/sbin/mysqld -V /usr/sbin/mysqld Ver 8.0.21 for Linux on x86_64 (Source distribution) [root@srv19 ~]# rpm -qi mysql-server Name : mysql-server Version : 8.0.21 Release : 1.module_el8.2.0+493+63b41e36 Architecture: x86_64 Install Date: Mon 28 Dec 2020 04:54:54 GMT Group : Unspecified Size : 113732452 License : GPLv2 with exceptions and LGPLv2 and BSD Signature : RSA/SHA256, Wed 16 Sep 2020 21:22:31 BST, Key ID 05b555b38483c65d Source RPM : mysql-8.0.21-1.module_el8.2.0+493+63b41e36.src.rpm Build Date : Tue 15 Sep 2020 19:54:05 BST Build Host : x86-02.mbox.centos.org Relocations : (not relocatable) Packager : CentOS BuildsysVendor : CentOS URL : http://www.mysql.com Summary : The MySQL server and related files Description : MySQL is a multi-user, multi-threaded SQL database server. MySQL is a client/server implementation consisting of a server daemon (mysqld) and many different client programs and libraries. This package contains the MySQL server and some accompanying files and directories.
Now we have MySQL-Server installed that we might need configure before use. To configure it we have MySQL configuration file located in /etc/my.cnf that could also include other directories as well.
Start MySQL Service
By-Default MySQL Server using data directory from “/var/lib/mysql” that should have separate mount point in case you are using MySQL Server in production Setup. So i have also created one another mount-point(/local/mysql) for it and configure details in MySQL configuration file.
In MySQL-Server 8 on CentOS8 we have /etc/my.cnf file like below.
[root@srv19 ~]# cat /etc/my.cnf # # This group is read both both by the client and the server # use it for options that affect everything # [client-server] # # include all files from the config directory # !includedir /etc/my.cnf.d
This configuration file don’t have any such special configuration parameter for MySQL-Server but include /etc/my.cnf.d directory which has another file(/etc/my.cnf.d/mysql-server.cnf) for server configuration, which has below parameter for configuration. I changed it a bit for my case like below
[root@srv19 ~]# egrep -v "^$|^#" /etc/my.cnf.d/mysql-server.cnf [mysqld] datadir=/local/mysql/ socket=/local/mysql/mysql.sock log-error=/var/log/mysql/mysqld.log pid-file=/run/mysqld/mysqld.pid max_connections = 200 [client] socket=/local/mysql/mysql.sock
Now we can start MySQL Server and enable it, so it will start auto during reboot.
[root@srv19 ~]# systemctl start mysqld.service [root@srv19 ~]# systemctl enable mysqld.service Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
We can see its status through systemctl status command.
[root@srv19 ~]# systemctl status mysqld.service ● mysqld.service - MySQL 8.0 database server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2020-12-28 06:17:58 GMT; 33s ago Process: 6618 ExecStopPost=/usr/libexec/mysql-wait-stop (code=exited, status=0/SUCCESS) Process: 6871 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS) Process: 6714 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS) Process: 6690 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS) Main PID: 6826 (mysqld) Status: "Server is operational" Tasks: 39 (limit: 11408) Memory: 458.2M CGroup: /system.slice/mysqld.service └─6826 /usr/libexec/mysqld --basedir=/usr Dec 28 06:16:12 srv19.geekpills.com systemd[1]: Starting MySQL 8.0 database server... Dec 28 06:16:12 srv19.geekpills.com mysql-prepare-db-dir[6714]: Initializing MySQL database Dec 28 06:17:58 srv19.geekpills.com systemd[1]: Started MySQL 8.0 database server.
Now to make to secure and prepare MySQL in proper way through MySQL Secure command in below way.
# mysql_secure_installation
Above command will set password,Remove anonymous users, Disallow root login remotely, Remove test database and access to it. These are some of basic steps to secure MySQL Server.
Below is Syntax for start/stop/restart/status to check MySQL Services
# systemctl status mysqld.service # systemctl stop mysqld.service # systemctl start mysqld.service # systemctl restart mysqld.service
We can also see MySQL log with below commands.
# journalctl -u mysqld.service -xe # tail -f /var/log/mysql/mysqld.log
Connection of MySQL Server
We can connect MySQL with below command.
[root@srv19 ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.21 Source distribution Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
We can check MySQL status.
mysql> status -------------- mysql Ver 8.0.21 for Linux on x86_64 (Source distribution) Connection id: 8 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 8.0.21 Source distribution Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8mb4 Db characterset: utf8mb4 Client characterset: utf8mb4 Conn. characterset: utf8mb4 UNIX socket: /local/mysql/mysql.sock Binary data as: Hexadecimal Uptime: 5 min 27 sec Threads: 2 Questions: 5 Slow queries: 0 Opens: 115 Flush tables: 3 Open tables: 36 Queries per second avg: 0.015 --------------
Create Database and provide access
We can create new MySQL database with below command.
mysql> create database wordpress; Query OK, 1 row affected (0.23 sec)
Create user with password to provide password for it.
mysql> create user 'bloguser'@'localhost' identified by 'Passw0rd@257'; Query OK, 0 rows affected (0.14 sec)
Provide permission on same database.
mysql> grant select, insert, update, delete on wordpress.* to 'bloguser'@'localhost'; Query OK, 0 rows affected (0.10 sec) mysql> grant all PRIVILEGES on wordpress.* to 'bloguser'@'localhost'; Query OK, 0 rows affected (0.19 sec)
We can login on MySQL on same Machine.
[root@srv19 ~]# mysql -u bloguser -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 8.0.21 Source distribution Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | wordpress | +--------------------+ 2 rows in set (0.00 sec) mysql> use wordpress; Database changed
So with above all commands we can see, we can install MySQL Server 8 on CentOS 8 Machine and can make database with User configuration on same.
Leave a Reply