当前位置:网站首页>CentOS7下mysql5.7.37的安装【完美方案】
CentOS7下mysql5.7.37的安装【完美方案】
2022-07-31 02:30:00 【倾心*】
不在CentOS安装mysql8.0的原因是对于一些中间件不兼容 比如mycat 会出现意想不到的bug 比如mycat连接mysql状态是连接成功,但是却进入不到数据库里面 出现数据库卡顿 报1184错误的现象 所以希望大家学习虚拟机的时候 mysql建议安装成mysql5.7的 本人亲自从mysql8.0.28回退到mysql5.7.37 中间各种错误 太痛苦了 所以在此提供mysql的安装与卸载教程 方便大家后续操作
centos下mysql安装步骤
进入官网MySQL :: Download MySQL Community Server (Archived Versions)
选择Red Hat Linux 7 与 centos7是一样的 互相兼容
选择版本和对应系统 下载第一个包 mysql-5.7.37-1.el7.x86_64.rpm-bundle.tar
查看是否有系统自带的mariadb和mysql
[[email protected] ~]# rpm -qa |grep mysql
[[email protected] ~]# rpm -qa |grep postfix
[[email protected] ~]# rpm -qa |grep mariadb
卸载命令
rpm -e --nodeps xxx
安装需要的依赖文件
yum -y install libaio
yum -y install net-tools
yum -y install perl
安装mysql5.7.37
最好将mysql一系列的文件归到一个文件夹里 然后在这个目录下解压
tar -xvf mysql-5.7.37-1.el7.x86_64.rpm-bundle.tar
按照顺序安装以下文件 必须按照顺序安装
rpm -ivh mysql-community-common-5.7.37-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.37-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.37-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.37-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.37-1.el7.x86_64.rpm
此外这里在提供mysql8.0.28的安装顺序,与mysql5.7还是有点区别的
1. mysql-community-common
2. mysql-community-client-plugins
3. mysql-community-libs
4. mysql-community-client
5. mysql-community-icu-data-files
6. mysql-community-server
启动mysql
先查看mysql的状态
命令1:
service mysqld status
命令2:
systemctl status mysqld
启动mysql服务
命令1
service mysqld start
命令2
systemctl start mysqld
查看mysql进程
ps -ef | grep mysqld
设置mysql开机自启(根据自身需求 可要可不要)
systemctl enable mysqld #设置开机启动
systemctl disable mysqld #关闭开机启动
获取mysql初始化密码
MySQL服务初始化密码是自动生成的我们需要通过查询 mysqld.log查询初始化密码
grep password /var/log/mysqld.log
A temporary password is generated for [email protected]: xxxxxx
(xxxxxx这就是初始密码 进入mysql复制即可)
登录MySQL修改初始化密码
mysql -uroot -p
初始化密码没修改的情况下是无法使用mysql服务的会提示必须充值秒才能进行操作
重置密码
mysql> set password = password("123456");
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
MySQL5.7版本的密码默认策略如下
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+--------------------------------------+--------+
如果密码设置的过于简单系统会提示不满足当前策略 会出现以下错误
[[email protected] opt]# mysql -uroot -p
mysql> set password = password("123456");
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
开发测试环境嫌麻烦的话可以通过以下命令修改密码策略
mysql> set global validate_password_policy=LOW;
mysql> set global validate_password_length=6;
再次查看默认密码策略
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 6 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | LOW |
| validate_password_special_char_count | 1 |
+--------------------------------------+-------+
7 rows in set (0.01 sec)
再次重置简单密码成功
mysql> set password = password("123456");
Query OK, 0 rows affected, 1 warning (0.00 sec)
设置mysql远程访问权限
需要在命令行执行开启远程访问命令
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
客户端连接MySQL服务
默认情况下Centos防火墙是开启状态 通过以下命令查询防火墙状态
systemctl status firewalld
方式1 关闭防火墙(企业环境不推荐)
# 关闭
systemctl stop firewalld.service
# 禁用
systemctl disable firewalld
方式2 开放mysql服务端口
# 添加需要放行的端口号
firewall-cmd --add-port=端口号/tcp --zone=public --pernament
# 移除需要放行的端口号
firewall-cmd --remove-port=端口号/tcp --zone=public --pernament
# 查看放行的端口号
firewall-cmd --list-ports
启动防火墙
# 开启
systemctl start firewalld.service
# 重启
systemctl restart firewalld.service
关闭或者放行端口号之后发现远程访问成功
至此centos下mysql的安装完美完成
边栏推荐
- 医疗影像领域AI软件开发流程
- String为什么不可变?
- 221. Largest Square
- 项目开发软件目录结构规范
- AtCoder Beginner Contest 261 部分题解
- Software testing basic interface testing - getting started with Jmeter, you should pay attention to these things
- Word/Excel fixed table size, when filling in the content, the table does not change with the cell content
- My first understanding of MySql, and the basic syntax of DDL and DML and DQL in sql statements
- Mathematical Ideas in AI
- mmdetection trains a model related command
猜你喜欢
String为什么不可变?
Detailed explanation of STP election (step + case)
multiplayer-hlap 包有问题,无法升级的解决方案
Basic learning about Redis related content
Installation, start and stop of redis7 under Linux
vlan间路由+静态路由+NAT(PAT+静态NAT)综合实验
Pythagorean tuple od js
Huawei od dice js
19. Support Vector Machines - Intuitive Understanding of Optimization Objectives and Large Spacing
The effective square of the test (one question of the day 7/29)
随机推荐
The Sad History of Image Processing Technology
STP选举(步骤+案列)详解
静态路由+PAT+静态NAT(讲解+实验)
General introduction to the Unity interface
Intel's software and hardware optimization empowers Neusoft to accelerate the arrival of the era of smart medical care
BAT卖不动「医疗云」:医院逃离、山头林立、行有行规
Problems that need to be solved by the tcp framework
f.grid_sample
LeetCode 1161 The largest element in the layer and the LeetCode road of [BFS binary tree] HERODING
【Bank Series Phase 1】People's Bank of China
Android's webview cache related knowledge collection
User interaction + formatted output
Introduction to flask series 】 【 flask - using SQLAlchemy
AtCoder Beginner Contest 261 Partial Solution
项目开发软件目录结构规范
StringJoiner详解
Static routing + PAT + static NAT (explanation + experiment)
怎样做好一个创业公司CTO?
基于FPGA的图像实时采集
The real CTO is a technical person who understands products