Loading

CentOS7 yum 安装 MySQL57

安装mysql57

# 查看repo仓库,一般默认情况下是8.0开启了,其他是禁用
yum repolist all | grep mysql

# 禁用不需要的版本
yum-config-manager --disable mysql80-community
# 启用指定版本
yum-config-manager --enable mysql57-community

# 安装mysql
yum install mysql-community-server

# 启动mysql
systemctl start mysqld

初始配置:修改密码

# 查看默认密码
grep "temporary password" /var/log/mysqld.log

# 使用默认密码登录
mysql -uroot -p

# 修改当前登录的用户的密码 >=5.7.6版本使用:
ALTER USER USER() IDENTIFIED BY 'pwd';


# 如果安装了密码校验插件validate_password,会提示密码安全度低,先查看一下密码策略配置信息
SHOW VARIABLES LIKE 'validate_password%';

# 将密码强度改成LOW,长度改成6
set global validate_password_policy=LOW; 
set global validate_password_length=6;

初始配置:修改端口

# 登录mysql,查看当前端口
show global variables like 'port';

# 修改端口,编辑/etc/my.cnf文件
root@test etc]# vi my.cnf

[mysqld]
port=33061
datadir=/var/lib/mysql

# 重启mysql服务
systemctl restart mysqld.service

开启远程连接

# 创建可远程的用户,并指定密码
create user "username"@"%" identified by "123456";

# 设置需要开启远程访问的数据库
use mysql;

# 查看用户和表
select host,user from user;

# 更新用户的登录地址,%表示任意IP
update user set host = '%' where user = 'root';

# 查看MySQL端口号是不是3306
show global variables like 'port';

# 刷新并写入权限
flush privileges;

# 关闭防火墙
systemctl disable firewalld

# 或者开放3306端口-----------------------------------

# 查看3306端口状态,no表示关闭
firewall-cmd --zone=public --query-port=3306/tcp

# 打开3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent 

# 重启防火墙
firewall-cmd --reload

# 查看已开放的端口
firewall-cmd --list-ports

参考链接

CentOS7 防火墙设置

posted @ 2021-11-21 23:58  西西嘻哈哈  阅读(164)  评论(0)    收藏  举报