yum 安装

yum install mysql-server mysql -y

启动服务

systemctl start mysqld

配置开机启动

systemctl enable mysqld

查看3306端口是否被监听
[root@leanote ~]# ss -lntp
State         Recv-Q        Send-Q               Local Address:Port                Peer Address:Port
LISTEN        0             128                        0.0.0.0:111                      0.0.0.0:*            users:(("rpcbind",pid=898,fd=4),("systemd",pid=1,fd=33))
LISTEN        0             32                   192.168.122.1:53                       0.0.0.0:*            users:(("dnsmasq",pid=1708,fd=6))
LISTEN        0             128                        0.0.0.0:22                       0.0.0.0:*            users:(("sshd",pid=1030,fd=5))
LISTEN        0             5                        127.0.0.1:631                      0.0.0.0:*            users:(("cupsd",pid=1033,fd=10))
LISTEN        0             128                              *:3306                           *:*            users:(("mysqld",pid=31814,fd=34))
LISTEN        0             128                           [::]:111                         [::]:*            users:(("rpcbind",pid=898,fd=6),("systemd",pid=1,fd=35))
LISTEN        0             128                           [::]:22                          [::]:*            users:(("sshd",pid=1030,fd=7))
LISTEN        0             5                            [::1]:631                         [::]:*            users:(("cupsd",pid=1033,fd=9))
LISTEN        0             70                               *:33060                          *:*            users:(("mysqld",pid=31814,fd=32))
[root@leanote ~]#
初始化MySQL

mysqld --initialize

查看密码
 cat /var/log/mysql/mysqld.log |grep password
2021-09-07T08:12:42.473145Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure optio
#这里提示root为空密码
进入数据库
mysql -uroot -p
#输入密码的时候直接回车
修改root密码
mysql> alter user root@localhost identified by "!QAZ2wsx";
Query OK, 0 rows affected (0.01 sec)
#密码修改成!QAZ2wsx