首先安装好mysql
[root@localhost ~]# yum -y install mysql-community-server
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
mysql-connectors-community | 2.6 kB 00:00:00
mysql-tools-community | 2.6 kB 00:00:00
mysql57-community | 2.6 kB 00:00:00
nginx | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/2): epel/x86_64/updateinfo | 1.0 MB 00:00:02
(2/2): epel/x86_64/primary_db | 7.0 MB 00:00:17
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-server.x86_64.0.5.7.43-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-client(x86-64) >= 5.7.9,它被软件包 mysql-community-server-5.7.43-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mysql-community-client.x86_64.0.5.7.43-1.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
====================================================================================================================
Package 架构 版本 源 大小
====================================================================================================================
正在安装:
mysql-community-server x86_64 5.7.43-1.el7 mysql57-community 184 M
为依赖而安装:
mysql-community-client x86_64 5.7.43-1.el7 mysql57-community 31 M
事务概要
====================================================================================================================
安装 1 软件包 (+1 依赖软件包)
总下载量:215 M
安装大小:915 M
Downloading packages:
(1/2): mysql-community-server-5.7.43-1.el7.x86_64.rpm | 184 MB 00:00:21
(2/2): mysql-community-client-5.7.43-1.el7.x86_64.rpm | 31 MB 00:00:23
--------------------------------------------------------------------------------------------------------------------
总计 9.1 MB/s | 215 MB 00:00:23
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : mysql-community-client-5.7.43-1.el7.x86_64 1/2
正在安装 : mysql-community-server-5.7.43-1.el7.x86_64 2/2
验证中 : mysql-community-server-5.7.43-1.el7.x86_64 1/2
验证中 : mysql-community-client-5.7.43-1.el7.x86_64 2/2
已安装:
mysql-community-server.x86_64 0:5.7.43-1.el7
作为依赖被安装:
mysql-community-client.x86_64 0:5.7.43-1.el7
完毕!
安装完成后启动服务,并查看启动状态
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2023-09-04 16:18:32 CST; 1s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 98736 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 98521 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 98739 (mysqld)
CGroup: /system.slice/mysqld.service
└─98739 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
9月 04 16:18:28 localhost.localdomain systemd[1]: Starting MySQL Server...
9月 04 16:18:32 localhost.localdomain systemd[1]: Started MySQL Server.
查看mysql临时密码
[root@localhost ~]# cat /var/log/mysqld.log| grep password
2023-09-04T08:18:30.073439Z 1 [Note] A temporary password is generated for root@localhost: 5<=w(EhWiGaf
使用临时密码登陆,并修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mysql@2023';
解释:root指的你的用户,localhost指本机,Mysql@2023指你要修改的密码(由于5.7版本密码增强,需要)
[root@localhost ~]# mysql -uroot -p'5<=w(EhWiGaf'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.43
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mysql@2023';
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
再次登陆时就是你输入的新密码啦
[root@localhost ~]# mysql -uroot -pMysql@2023