写在前面:如果有得选,我一定要用bt一键安装>>>

原文继续:
mysql官网下载mysql-5.7.25-el7-x86_64.tar.gz
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.25-el7-x86_64.tar.gz

一、卸载系统自带的Mariadb
rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

二、删除/etc下my.cnf配置文件(如果存在的话)、检查mysql是否存在
rm -rf /etc/my.cnf
rpm -qa | grep mysql

三、检查mysql用户组、用户是否存在,不存在则创建
cat /etc/group | grep mysql
cat /etc/passwd | grep mysql
groupadd mysql
useradd -g mysql mysql

四、解压mysql,移动到/usr/local/mysql下,更改文件归属为mysql

tar -zxvf mysql-5.7.25-el7-x86_64.tar.gz 
mkdir -p /usr/local/mysql
mv /usr/local/mysql-5.7.25-el7-x86_64/* /usr/local/mysql/
mkdir /usr/local/mysql/data
mkdir /usr/local/mysql/log
touch /usr/local/mysql/log/mysqld.log
chown -R mysql /usr/local/mysql/
chgrp -R mysql /usr/local/mysql/

五、安装
/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

PS:需安装libaio库
yum install libaio* -y

六、新建配置文件my.cnf,启动
vim /etc/my.cnf
chown 777 /etc/my.cnf

[mysqld]
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
user=mysql
symbolic-links=0
lower_case_table_names=1
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB
lower_case_table_names = 1

group_concat_max_len = 400000
max_allowed_packet = 51200
tmp_table_size = 256M
max_heap_table_size = 256M
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

[client]
port=3306
 
[mysqld_safe]
log-error=/usr/local/mysql/log/mysqld.log

启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
service mysqld start
停止
service mysqld stop
重启
service mysqld restart

七、添加环境变量
vim /etc/profile

添加mysql环境变量

# MYSQL
export MYSQL_HOME="/usr/local/mysql/"
export PATH="$PATH:$MYSQL_HOME/bin"

使环境变量生效
source /etc/profile

八、获取初始密码,连接mysql,更改默认密码,允许远程访问
获取初始密码
cat /root/.mysql_secret
修改密码

[root@centos7 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25
 
Copyright (c) 2000, 2019, 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> set PASSWORD = PASSWORD('123456789');
Query OK, 0 rows affected, 1 warning (0.00 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

允许远程访问

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Database changed
mysql> select host,user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
3 rows in set (0.00 sec)
 
mysql> create user 'root'@'%' identified by '123456789';
Query OK, 0 rows affected (0.00 sec)

grant all privileges on *.* to root@'%' identified by '123456789';

退出数据库
exit;

3306端口防火墙添加规则
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload