与CentOS7对应的是源为
https://repo.mysql.com/mysql84-community-release-el7-1.noarch.rpm
使用包管理器RPM安装
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2023
rpm -Uvh https://repo.mysql.com/mysql84-community-release-el7-1.noarch.rpm
yum安装
yum -y install mysql-community-server
查看安装位置并启动
[root@localhost ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/man/man1/mysql.1.gz
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]# systemctl status mysqld
查看 MySQL 服务进程
[root@localhost ~]# ps axj | grep mysqld
1 6085 6085 6085 ? -1 Ssl 27 0:03 /usr/sbin/mysqld
3818 6179 6178 3818 pts/0 6178 R+ 0 0:00 grep --color=auto mysqld
登录 MySQL
查看配置文件/etc/my.cnf
cat /etc/my.cnf
log-error 的内容 /var/log/mysqld.log 就是 MySQL 日志文件的路径
log-error=/var/log/mysqld.log
[root@localhost ~]# grep "temporary password" /var/log/mysqld.log
2024-12-12T05:54:36.633865Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Ukzur#ajq2U_
[root@localhost ~]# mysql -u root -p
修改密码
alter user 'root'@'localhost' identified by 'Abcd1234_efghi‘
注意,密码有要求,例如包括‘_’符号等,不然可能会出现
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements