Centos7 安装和配置MySQL5.7

第一步,下载MySQL安装

[[email protected] ~]# cd /home/data/
[[email protected] data]# ls
[[email protected] data]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
如果提示wget命令不存在,先执行

yum -y install wget
下载完成后

多了一个mysql57-xxx的文件,这个就是mysql安装源

安装mysql安装源

[[email protected] data]# yum -y localinstall mysql57-community-release-el7-11.noarch.rpm 
第二步,在线安装MySQL

[[email protected] data]# yum -y install mysql-community-server
下载的东西有点多,需要等待一会

第三步,启动MySQL服务

[[email protected] data]# systemctl start mysqld
第四步,设置开机启动

[[email protected] data]# systemctl enable mysqld
 
[[email protected] data]# systemctl daemon-reload
第五步,修改root登录密码

mysql安装完成之后,会在/var/log/mysqld.log文件中给root生成了一个临时的默认密码。

[[email protected] data]# vim /var/log/mysqld.log

Centos7 安装和配置MySQL5.7


复制此密码,使用此密码登录root

[[email protected] data]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25
 
Copyright (c) 2000, 2019, 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> 
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '[email protected]';
Query OK, 0 rows affected (0.01 sec)
 
 mysql5.7默认密码策略要求密码必须是大小写字母数字特殊字母的组合,至少8位

第六步,设置允许远程登录

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '[email protected]' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
第七步,退出

mysql> exit
Bye
第八步,防火墙开放3306端口

[[email protected] data]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
 
success
 
[[email protected] data]# firewall-cmd --reload
 
success
 
[[email protected] data]# 
第九步,配置mysql默认编码为utf-8

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置

character_set_server=utf8

init_connect='SET NAMES utf8'

Centos7 安装和配置MySQL5.7

:wq!保存退出

第十步,重启MySQL

[[email protected] data]# systemctl restart mysqld
第十一步,登录root用户查看编码

Centos7 安装和配置MySQL5.7

第十二步,测试远程连接