Install MySQL under Linux (CentOS 7)

MariaDB is installed by default in CentOS, but what we need is MySQL. Installing MySQL can overwrite MariaDB

The MariaDB database management system is a branch of MySQL, which is mainly maintained by the open source community and is licensed under GPL. One of the reasons for the development of this branch is that after Oracle acquired MySQL, there is a potential risk of closing MySQL to the source, so the community uses branching to avoid this risk. The purpose of MariaDB is to be fully compatible with MySQL, including API and command line, so that it can easily become a substitute for MySQL.

First install the Yum Repository of MySQL

Yum helped us manage the dependencies of various rpm packages. It is a rpm-based package manager that can automatically download and install RPM packages from a specified server. It can automatically handle dependencies and install all dependent software packages at once. No need to download and install again and again.

All operations are switched to the root user
Install MySQL official Yum Repository

[ root@localhost~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

Download rpm package

[ root@localhost~]# yum -y install mysql57-community-release-el7-10.noarch.rpm

Install MySQL service

[ root@localhost~]# yum -y install mysql-community-server

It takes a long time to perform the installation service. Please wait patiently. I asked y/n? Enter y and enter

Start the mysql service:

[ root@localhost~]# systemctl start  mysqld.service

View the running status of mysql:

[ root@localhost~]# systemctl status mysqld.service

You can see the running status of the mysql service, and the following information appears, where Active represents the status after the service is started, which is active (running), and after it is stopped, it is inactive (dead)

[ root@localhost ~]# systemctl status mysqld.service
● mysqld.service - MySQL Server
 Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
 Active: active (running)since March 2018-02-14 10:12:13 CST; 3min 31s ago
  Docs: man:mysqld(8)
   http://dev.mysql.com/doc/refman/en/using-systemd.html
 Process: 1424 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
 Process: 935 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 1427 (mysqld)
 CGroup: /system.slice/mysqld.service
   └─1427 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid...

2 Month 14 10:11:53 localhost.localdomain systemd[1]: Starting MySQL Server...
2 Month 14 10:12:13 localhost.localdomain systemd[1]: Started MySQL Server.

You can also restart the service

root@localhost~]# service mysqld restart

Out of service

[ root@localhost~]# systemctl stop mysqld.service

After the installation is complete, there is a root user by default, the initial password has been set, we need to obtain this initial password to log in and then modify it

In order to enhance security, MySQL 5.7 randomly generates a password for the root user. In the error log, regarding the location of the error log, if the RPM package is installed, the default is /var/log/mysqld.log.
You can view the temporary password only after starting mysql once

Check the initial password by the following command, the character after the colon is the password

grep 'temporary password'/var/log/mysqld.log

Login root user

[ root@localhost~]# mysql -u root -p

Prompt for the password, enter the initial password, after using the password, you need to set your own password, but mysql has a password requirement, we want to set a simple password must modify the constraints, modify two global parameters:
validate_password_policy represents the password policy, the default is 1: meet the length, and must contain numbers, lowercase or uppercase letters, special characters. Set to 0 to determine the standard of the password based on the length of the password. Be sure to modify the two parameters first and then modify the password

mysql> set global validate_password_policy=0; 

validate_password_length represents the length of the password, the minimum value is 4

mysql>setglobal validate_password_length=4;

Change the password to root, and then you can use that password to log in

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';

The directory where the main configuration of mysql in CentOS is located:

  1. /etc/my.cnf This is the main configuration file of mysql
  2. /var/lib/mysql Database file storage location of mysql database
  3. /var/log mysql database log output storage location

The firewall opens port 3306

The syntax command is as follows: enable zone port and protocol combination

firewall-cmd [--zone=<zone>]--add-port=<port>[-<port>]/<protocol>[--timeout=<seconds>]

This will enable the combination of ports and protocols.
The port can be a single port or a range of ports -.
Protocol can be tcp or udp

Check firewalld status

systemctl status firewalld

Open firewalld

systemctl start firewalld

Open port

// --permanent,Invalid after restart without this parameter
firewall-cmd --zone=public--add-port=3306/tcp --permanent 

firewall-cmd --zone=public--add-port=1000-2000/tcp --permanent 

Reload

firewall-cmd --reload

View

firewall-cmd --zone=public--query-port=80/tcp

delete

firewall-cmd --zone=public--remove-port=80/tcp --permanent

Recommended Posts

Install MySQL under Linux (CentOS 7)
Install mysql5.7 under CentOS7
Install mysql under Centos 7
Install mysql5.1 under CentOS6.5
Install mysql8.0.13 version under Linux CentOS7 system
CentOS 6.8 under linux install mongodb
CentOS7.2 install Mysql5.7.13
CentOS7 install MySQL
CentOS install mysql
CentOS7 install mysql
CentOS 7 install MySQL 5.6
CentOS8 install MySQL8.0
CentOS7 install mysql8
CentOS7 install MySQL8
centos 7.5 install mysql5.7.17
Install MySQL on Linux CentOS7 (Windows)
Install MySQL5.7 in centos7
Install mysql under Ubuntu 16.04
Install ActiveMQ under Centos7
Install PostgreSQL12 under CentOS7
Install CentOS under VMware
Linux Centos7 install jdk1.8
CentOS 7.2 Yum install MySQL 5.6
CentOS (linux) install PostgreSQL
Centos7 install Mysql8 tutorial
Centos manually install mysql8
Centos7 install Mysql database
Install Jenkins under Centos 7
Install MariaDB under MariaDB Centos7
Install MySQL under Ubuntu
Centos 7 install JDK (Linux install jdk)
Install MySQL 8.x from source code under CentOS7
Linux (CentOS7) using RPM to install mysql 8.0.11 tutorial
Know Linux and install CentOS
centos install mysql through yum
Install python environment under Linux
Linux Centos7 install redis tutorial
Install Oracle11gR2 database under CentOS6.9
3 partitioning tools under CentOS Linux
Install Java JDK8 under CentOS6
Centos6 install mysql 5.7.x series
Install MongoDB database under CentOS7
CentOS8 install MySQL8 (pro test)
Install Mesos tutorial under CentOS7
1.5 Install Centos7
Compile and install Lnmp shell script under Linux centos
How to install MySQL on CentOS 8
CentOS7 yum install and start mysql
CentOS Yum compile and install MySQL 5.6
Compile and install LAMP under Centos 5.2
[Introduction to redis] Install redis under Centos
CentOS 7 install Nginx, PHP, MySQL packages
Install MySql with Docker in CentOS7
Linux CentOS 7 install JDK detailed steps
CentOS7 yum install and start mysql
Install MySQL under Ubuntu 18.04 (graphic tutorial)
Install Harbor mirror warehouse under CentOS
Centos7 and centos8 install mysql5.6 5.7 8.0 so simple
Centos yum install mysql5.6 or above
​Install Oracle database on CentOS Linux
Install Python3 and ansible under CentOS8