wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
yum -y install mysql57-community-release-el7-11.noarch.rpm
yum install mysql-community-server

如果出错

warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-server-5.7.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


The GPG keys listed for the "MySQL 5.7 Community Server" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.


 Failing package is: mysql-community-server-5.7.37-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

导入新的KEY

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

再重新安装

yum install mysql-community-server

在这里插入图片描述

启动mysql

systemctl start  mysqld.service

查看运行状态

systemctl status mysqld.service
[root@iZwz98ej4pmj4inmz5vfa3Z ~]# systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2022-03-21 17:26:12 CST; 1min 16s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 27795 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 27743 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 27797 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─27797 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/my...

Mar 21 17:26:08 iZwz98ej4pmj4inmz5vfa3Z systemd[1]: Starting MySQL Server...
Mar 21 17:26:12 iZwz98ej4pmj4inmz5vfa3Z systemd[1]: Started MySQL Server.

更改密码

找root的密码

 grep "password" /var/log/mysqld.log

[root@iZwz98ej4pmj4inmz5vfa3Z ~]# grep “password” /var/log/mysqld.log
2022-03-21T09:26:09.941436Z 1 [Note] A temporary password is generated for root@localhost: m9C5fdlw;Vpd
进入数据库(密码是上面查出来的m9C5fdlw;Vpd,每个人不一样)

mysql -uroot -p

使用上面查询出来 的密码进行登录
在这里插入图片描述
修改密码(BY后面那个引号里面的是密码)

 ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
 ALTER USER 'root'@'localhost' IDENTIFIED BY 'ZAQ!xsw2';

提示这个是因为密码太简单,设置一个复杂的密码就可以成功
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
开启mysql的远程访问
用%代表所有,想要限制就用ip替换%即可;
ZAQ!xsw2是root账号对应的密码

grant all privileges on *.* to 'root'@'%' identified by 'ZAQ!xsw2' with grant option;

刷新退出

 flush privileges; 

添加mysql端口3306

遇到报错

 firewall-cmd --zone=public --add-port=3306/tcp --permanent

FirewallD is not running
解决:开启防火墙
对了,要开启防火墙(为了安全)
Active: inactive (dead) 防火墙没开
Active: active (running) 防火墙已开启

systemctl status firewalld

在这里插入图片描述
开启防火墙:

     Docs: man:firewalld(1)
[root@iZwz98ej4pmj4inmz5vfa3Z ~]# systemctl start firewalld
[root@iZwz98ej4pmj4inmz5vfa3Z ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2022-03-21 17:40:25 CST; 7s ago
     Docs: man:firewalld(1)
 Main PID: 27847 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─27847 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

Mar 21 17:40:25 iZwz98ej4pmj4inmz5vfa3Z systemd[1]: Starting firewalld - dyna...
Mar 21 17:40:25 iZwz98ej4pmj4inmz5vfa3Z systemd[1]: Started firewalld - dynam...
Mar 21 17:40:25 iZwz98ej4pmj4inmz5vfa3Z firewalld[27847]: WARNING: AllowZoneD...
Hint: Some lines were ellipsized, use -l to show in full.
[root@iZwz98ej4pmj4inmz5vfa3Z ~]# 

添加端口、重启防火墙

[root@iZwz98ej4pmj4inmz5vfa3Z ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@iZwz98ej4pmj4inmz5vfa3Z ~]# firewall-cmd --reload
success
[root@iZwz98ej4pmj4inmz5vfa3Z ~]# 

默认编码修改

 vi /etc/my.cnf
[client]
default-character-set=utf8
character-set-server=utf8
collation-server=utf8_general_ci

在对应位置添加下面两段
在这里插入图片描述
在这里插入图片描述

重启mysql

service mysqld restart
create database  uav default charset utf8 collate utf8_general_ci;

win 下载地址:mysql5.7

本内容为合法授权发布,文章内容为作者独立观点,不代表开发云立场,未经允许不得转载。

CSDN开发云