1、下载MySQL官方的 Yum Repository
cd ~ && mkdir /usr/mysql && cd /usr/mysql
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
2、用yum安装Yum Repository
yum -y install mysql57-community-release-el7-10.noarch.rpm
3、安装MySQL服务器
yum -y install mysql-community-server
4、Mysql设置
启动Mysql数据库:
systemctl start mysqld.service
查看Mysql运行状态:
systemctl status mysqld.service
出现以下信息,表示MySQL正常运行
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2022-09-06 16:28:18 CST; 18s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 19800 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 19747 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 19803 (mysqld)
CGroup: /system.slice/mysqld.service
└─19803 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Sep 06 16:28:14 hecs-235841 systemd[1]: Starting MySQL Server...
Sep 06 16:28:18 hecs-235841 systemd[1]: Started MySQL Server.
5、修改数据库密码
①
此时MySQL已经开始正常运行,不过要想进入MySQL还得先找出此时root用户的密码,通过如下命令可以在日志文件中找出密码:
grep "password" /var/log/mysqld.log
②
执行上述命令的结果
[root@hecs-235841 mysql]# grep "password" /var/log/mysqld.log
2022-09-06T08:28:15.815694Z 1 [Note] A temporary password is generated for root@localhost: ozhw9tuaCi*A
密码是结果root@localhost:之后的字段
③
使用此命令进入数据库:
mysql -uroot -p
④
修改数据库进入密码:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
其中‘new password’替换成你要设置的密码,注意:密码设置必须要大小写字母数字和特殊符号(,/’;:等),不然不能配置成功