当前位置:网站首页>Centos7通过Yum安装MySql5.7并开启远程访问
Centos7通过Yum安装MySql5.7并开启远程访问
2022-07-15 20:01:00 【19921106】
前言
Mysql大家都懂的了,我就不过多做介绍了,直接进行mysql的安装吧,下面记录如果通过yum安装mysql5.7,此方法照样适用于安装8.0,5.6,5.5等mysql版本
正文
1. 删除mariadb
centos7 默认会安装mysql的另一个分支版本mariadb,在安装mysql前,需要将其删除
# 查出mariadb的rpm包
$ rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
# 忽略依赖关系,删除此包
$ rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_642. 添加官方yum源并安装mysql
访问mysql官方yum源下载地址,选择系统,点击下载,进入页面,复制下载连接


# 下载安装此yum仓库
$ rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
# 安装完成后,此yum源仓库默认是安装mysql最新版8.0版本。
# 需要我们修改一下文件中的下列项,使其下载5.7版本,如果要安装别的版本,就打开对应版本,将别的版本关闭即可。
$ vim /etc/yum.repos.d/mysql-community.repo
----------------------------------------------------------------
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1 # 这里将0改为1,开启5.7版本
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0 # 这里将1改为0,关闭8.0版本
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
----------------------------------------------------------------
# 修改完成后,安装mysql5.7
$ yum install -y mysql-community-server安装完成后,配置文件为 /etc/my.cnf 根据实际情况进行配置。
3. 启动服务,开启远程访问
# 启动mysql服务
$ systemctl start mysqld
# 设为开启自启动
$ systemctl enable mysqld
# 第一次启动mysql后,会自动生成一个初始密码在日志文件中,默认的日志文件路径为:/var/log/mysqld.log
# 找出初始化密码
$ cat /var/log/mysqld.log |grep password
2019-06-18T12:12:04.161088Z 1 [Note] A temporary password is generated for [email protected]: 2%w)IDysCVZQ
# 这里密码就是上面输出的那段,使用此密码登录mysql
$ mysql -u root -p
# 复制密码输出,进入mysql
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.26
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>
# 修改密码,mysql5.7的默认密码强度很高,需要有大小写,符号和数字,长度大于6,缺一不可
mysql> alter user 'root'@'localhost' identified by 'your_password';
Query OK, 0 rows affected (0.00 sec)
# 如果你不像要这么复杂的密码,修改密码强度设定为最低,即只判断密码长度
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
# 开启远程访问
$ grant all privileges on *.* to 'root'@'%' identified by 'your_password';
Query OK, 0 rows affected, 1 warning (0.00 sec)
# 刷新权限生效
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
# 到此就完成了mysql的最初设置了,现在就可以用账号密码,访问此mysql服务了
# 访问之前别忘了要打开数据库3306端口
$ firewall-cmd --add-port=3306/tcp --permanent
$ firewall-cmd --reload结束
ok,就这么简单的就完成了mysql5.7的yum安装,通过此方法同样可以安装mysql5.5,5.6,8.0这些版本。只要官方的yum仓库支持就行,非常简单方便。
边栏推荐
- GD32F4xx IAP 升级思路
- Leetcode-128-longest continuous sequence
- 5个时间序列预测的深度学习模型对比总结:从模拟统计模型到可以预训练的无监督模型
- Codeforces Global Round 21 B. NIT Destroys the Universe
- exness:原油止跌反弹,晚间关注美国恐怖数据表现
- 量子保密通信浅析
- Timeline and playable cause unity crash problem record
- 【ARCGIS创建中国南海诸岛及九段线小图框】
- 模拟卷Leetcode【普通】1996. 游戏中弱角色的数量
- Research on data security governance in China
猜你喜欢
随机推荐
Codeforces Round #803 (Div. 2) C. 3SUM Closure
Role based security access control strategy for virtual machine in cloud environment
STM32F030外部中断配置
Codeforces Round #802 C. Helping the Nature
腾势全新豪华中大型MPV曝光,安全、舒适一个不落
atcoder ABC 232 B~E题解
SQL也能玩转AI ?没错!MLOps Meetup V3 回顾|OpenMLBD+SQLFlow+Byzer
答读者问(6):单细胞TPM矩阵如何分析?
Analysis on the application security and technology of electronic signature
Leetcode-128-longest continuous sequence
面试基础题
Access control settings
【快速下载VsCode】
C#将数据库连接方式写到配置文件中
Nodejs直接使用proto文件
Codeforces Round #806 (Div. 4) A - G
Codeforces Round #804 B Almost Ternary Matrix
包过滤规则
基于角色的云环境下虚拟机安全访问控制策略
A privacy protection and authentication method for fingerprint biometrics









