Install MySQL in CentOS 7 environment

888u

Last update at :2024-02-08,Edit by888u

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

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 developing this branch is that after Oracle acquired MySQL, there was a potential risk of closing MySQL as a source, so the community adopted a branch approach to avoid this risk. MariaDB aims to be fully compatible with MySQL, including API and command line, making it an easy MySQL replacement.

First install MySQL’s Yum Repository

Yum helps us manage the dependencies of various rpm packages. It is an rpm-based software package manager that can automatically download and install RPM packages from a designated server. It can automatically handle dependencies and install all dependencies at once. Software package, no need to download and install it again and again.

All operations are performed by switching to the root user. Install MySQL official Yum Repository

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

Download rpm package

yum -y install mysql57-community-release-el7-10.noarch.rpm

Install MySQL service

yum -y install mysql-community-server

It takes a long time to install the service. Wait patiently. I asked y/n once in the middle? Enter y and press Enter

Start the mysql service:

systemctl start mysqld.service

View mysql running status:

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 starting the service, which is active (running), and after stopping, it is inactive (dead)

systemctl status mysqld.service ● mysqld.service – MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 三 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... February 14 10:11:53 localhost.localdomain systemd[1]: Starting MySQL Server... February 14 10:12:13 localhost.localdomain systemd[1]: Started MySQL Server.

You can also restart the service

service mysqld restart

Stop service

systemctl stop mysqld.service

After the installation is completed, there will be a root user by default, and the initial password has been set. We need to obtain this initial password and then modify it after logging in

In order to enhance security, MySQL5.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 if you have started mysql once

Check the initial password through the following command. The characters after the colon are the password

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

Log in as root user

mysql -u root -p

Prompt to enter the password, enter the initial password. After using this password, you need to set your own password, but mysql has password requirements. If we want to set a simple password, we must modify the constraints and modify two global parameters: validate_password_policy represents the password policy, the default is 1: meets the length, and must contain numbers, lowercase or uppercase letters, and special characters. The criterion for judging passwords when set to 0 is based on the length of the password. Be sure to modify the two parameters first before changing the password

mysql> set global validate_password_policy=0;

validate_password_length represents the password length, the minimum value is 4

mysql> set global validate_password_length=4;

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

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

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

/etc/my.cnf This is the main configuration file of mysql /var/lib/mysql The database file storage location of the mysql database /var/log Mysql database log output storage location

Recommended site searches: European servers, icp registration query system, expired domain name query, Tencent cloud server 12 yuan a year, Beijing domain name registration, registration query Ministry of Industry and Information Technology domain name registration website, rent a server, Hong Kong virtual host space, free IP ,

Install MySQL in CentOS 7 environment

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码