Installing MySQL
On CentOS 8, MySQL version 8 is available from the default repositories. In this guide I will install the server and create some initial user and databases.
sudo yum install mysql-server
. . . Install 49 Packages Total download size: 46 M Installed size: 252 M Is this ok [y/N]: y
sudo systemctl start mysqld sudo systemctl enable mysqld sudo systemctl status mysqld
If MySQL was successfully started, the output will show that the MySQL service is active: Output
● mysqld.service - MySQL 8.0 database server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-03-12 14:07:41 UTC; 1min 7s ago
Main PID: 15723 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 5056)
Memory: 474.2M
CGroup: /system.slice/mysqld.service
└─15723 /usr/libexec/mysqld --basedir=/usr
Mar 12 14:07:32 cent-mysql-3 systemd[1]: Starting MySQL 8.0 database server...
Mar 12 14:07:32 cent-mysql-3 mysql-prepare-db-dir[15639]: Initializing MySQL database
Mar 12 14:07:41 cent-mysql-3 systemd[1]: Started MySQL 8.0 database server.
Secure it
MySQL includes a security script that allows you to change some default configuration options in order to improve MySQL’s security.
sudo mysql_secure_installation
This will take you through a series of prompts asking if you want to make certain changes to your MySQL installation’s security options. The first prompt will ask whether you’d like to set up the Validate Password Plugin, which you can use to test the strength of your MySQL password.
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: Y
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Regardless of whether you choose to set up the Validate Password Plugin, the next prompt will be to set a password for the MySQL root user. Enter and then confirm a secure password of your choice: Output
Please set the password for root here.
New password:
Re-enter new password:
If you used the Validate Password Plugin, you’ll receive feedback on the strength of your new password. Then the script will ask if you want to continue with the password you just entered or if you want to enter a new one. Assuming you’re satisfied with the strength of the password you just entered, enter Y
to continue the script: Output
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
Configure Firewall ports
If you have firewalld installed and running, you need to add the service to it.
$ sudo systemctl start firewalld $ sudo systemctl enable firewalld $ sudo systemctl status firewalld $ sudo firewall-cmd --zone=public --add-service=mysql --permanent success $ sudo firewall-cmd --reload success
Create first user and databases
mysql -u root -p
Create full admin user
mysql> create user saeed@`%` identified by "yoursTR0n6pass";
mysql>
grant all privileges on *.* to saeed;
Create a database and a user with full access to that database
mysql>
create database mycatdb;mysql>
create user mycat@`%` identified by "yourcatssTR0n6pass";
grant all privileges on mycatdb.* to
mysql>
mycat
;mysql>
flush privileges;
Restore a db from dump
mysql -u root -p mysql> use mycatdb; Database changed mysql> source /home/saeed/mycat-db-dump-20200409-084604.sql