Reference article address:
https://www.linuxidc.com/Linux/2018-05/152574.htm
The yum source of Centos 7 no longer supports mysql, and now the default embedded database is mariadb,
Background introduction:
The MariaDB database management system is a branch of MySQL, which is mainly maintained by the open source community and is licensed under the GPL. One of the reasons for the development of this branch is that after Oracle acquired MySQL, there is a potential risk of closing the source of MySQL, so the community uses a branch to avoid this risk. MariaDB's purpose is to be fully compatible with MySQL, including API and command line, so that it can easily become a substitute for MySQL.
So if we install MySQL under CentOS7, we need to add additional sources ourselves:
The specific steps are as follows:
1. Download and add the repository
yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
2. Install the MySQL 5.7 package
Install MySQL like other packages using yum, and install the development kit
yum install mysql-server mysql-client mysql-devel
3. Start Mysql
systemctl enable mysqld
systemctl start mysqld
View Mysql service status
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 日 2019-05-27 07:52:03 CST; 1min 8s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 3743 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 3835 (mysqld)
Status: "SERVER_OPERATING"
CGroup: /system.slice/mysqld.service
└─3835 /usr/sbin/mysqld5月 27 07:49:51 localhost.localdomain systemd[1]: Starting MySQL Server...
5月 27 07:52:03 localhost.localdomain systemd[1]: Started MySQL Server.
4. MySQL initialization
When the MySQL server is started for the first time, a temporary password is generated for the MySQL root user. You can find the password by running the following command:
sudo grep 'temporary password' /var/log/mysqld.log
The output should look like this:
2018-05-26T23:50:09.270656Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: xwEPP-Fd2zcf
Make a note of the password xwEPP-Fd2zcf , because the next command will ask you to enter a temporary root password.
Run the mysql_secure_installation command to improve the security of MySQL installation
mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
After entering the xwEPP-Fd2zcf temporary password, the system will ask you to set a new password for the root user. The password must contain at least 8 characters and at least one uppercase letter, one lowercase letter, one number, and one special character.
Sample output:
The existing password for the user account root has expired. Please set a new password.
New password:
Re-enter new password:
The script will also ask you to delete anonymous users, restrict root user access to the local computer and delete the test database. You should answer "y" (yes) to all questions.
Finally, execute mysql -u root -p to connect to MySQL
Finally connect to MySQL
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.11 MySQL Community Server - GPLCopyright (c) 2000, 2018, 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.