Centos7 安装和配置MySQL5.7
1、下载mysql的rpm包
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
2、安装mysql安装源
yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
3、在线安装mysql
yum -y install mysql-community-server
下载的东西较多,请耐心等待
4、启动MySQL服务
systemctl start mysqld
5、设置开机启动
systemctl enable mysqld
systemctl daemon-reload
6、修改root登录密码
mysql安装完成之后,会在/var/log/mysqld.log文件中给root生成了一个临时的默认密码。
vim /var/log/mysqld.log
复制此密码,使用此密码登录root
[root@pyserver ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.29 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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>
修改密码, mysql5.7默认密码策略要求密码必须是大小写字母数字特殊字母的组合,至少8位
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Ming1234@';
允许远程登陆
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Ming1234@' WITH GRANT OPTION;
刷新权限
flush privileges; #刷新当前配置
7、配置防火墙
# 1> 开放3306端口(虚拟机下使用,云服务器请配置服务)
# 设置 iptables service
yum -y install iptables-services
# 如果要修改防火墙配置,如增加防火墙端口3306
vi /etc/sysconfig/iptables
# 增加规则
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT #保存退出后
# 配置防火墙:
systemctl restart iptables.service # 重启防火墙使配置生效
systemctl enable iptables.service # 设置防火墙开机启动
8、配置mysql默认编码为utf-8
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置
character_set_server=utf8
init_connect=‘SET NAMES utf8’
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fS0DXShX-1602230947110)(.\mysql57安装\配置mysql默认编码为utf-8.png)]
9、重启mysqld
systemctl restart mysqld
ES utf8’
[外链图片转存中…(img-fS0DXShX-1602230947110)]
9、重启mysqld
systemctl restart mysqld