Centos 上通过RPM包安装 Mysql

1. 安装RPM包MySQL数据库

yum -y install mysql*

2. MySQL服务管理

2.1 开机自动启动

systemctl enable mysqld.service

2.2 启动服务

systemctl start mysqld.service

2.3 关闭服务

systemctl stop mysqld.service

2.4 重启服务

systemctl restart mysqld.service

2.5 查看状态

systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-09-20 05:04:01 UTC; 1min 28s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 29354 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 29390 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─29390 /usr/sbin/mysqld

Sep 20 05:03:59 ip-172-31-2-29.eu-central-1.compute.internal systemd[1]: Starting MySQL S...
Sep 20 05:04:01 ip-172-31-2-29.eu-central-1.compute.internal systemd[1]: Started MySQL Se...
Hint: Some lines were ellipsized, use -l to show in full.

3.查看进程

方法1:

pstree |grep mysqld

方法2:

ps -ef |grep mysqld
root      2420 17505  0 05:13 pts/3    00:00:00 grep --color=auto mysqld

mysql    29390     1  0 05:03 ?        00:00:03 /usr/sbin/mysqld

4.查看端口

netstat -tunpl |grep mysqld

5. 修改配置文件

vi /etc/my.cnf.d/mysql-server.cnf
port=3000