CentOS7通过rpm安装MySQL5.7.30
上次介绍了Redis的安装方法,这回再来个MySQL吧,把平时最常用的安装都复习下,本来这次讲的应该是在CentOS7下通过rpm安装MySQL 5.7.29,结果研究源码安装时间过长出新版本了~ 那就直接再重装遍MySQL 5.7.30复习下,不说废话直接上傻瓜式教程。
1. 下载MySQL的rpm安装包
# 安装wget
yum install –y wget
# 下载mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar
# 若下载失败(下载成功此步跳过),可安装rz从本地上传mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar
yum -y install lrzsz
rz
1234567
2. 安装依赖
# 先检查有没有安装过mysql或mariadb
rpm -qa |grep mysql
rpm -qa |grep mariadb
# 我有个mariadb-libs-5.5.64-1.el7.x86_64,把它给卸载了
rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
# 安装libaio、perl、net-tools库,要不就会报错 balabala...
yum -y install libaio perl net-tools
12345678
3. 安装MySQL
# 建个目录存放解压文件
mkdir mysql-5.7.30
# 解压缩
tar -xvf mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar -C mysql-5.7.30
# 进入目录准备安装
cd mysql-5.7.30
# 开始安装,-ivh 其中i表示安装,v表示显示安装过程,h表示显示进度
rpm -ivh mysql-community-common-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.30-1.el7.x86_64.rpm
1234567891011
4. 启动MySQL
# 启动mysqld服务
systemctl start mysqld
# 下面列出其余systemctl命令(不用运行)
# 查看mysqld服务状态
systemctl status mysqld
# 停止mysqld服务
systemctl stop mysqld
# 重新启动mysqld服务
systemctl restart mysqld
# 配置mysqld开机自动启动
systemctl enable mysqld
# 配置mysqld开机不自动启动
systemctl disable mysqld
1234567891011121314
5. 登录MySQL修改密码
# 查询生成的临时密码
grep "password" /var/log/mysqld.log
# 登录mysql
mysql -uroot -p
# Enter password: (输入查询到的临时密码)
# 因为是本地测试环境,所以想把密码改的简单点
# 查询密码校验配置的系统变量
SHOW VARIABLES LIKE 'validate_password%';
# 设置密码校验策略(0 or LOW),要不密码太LOW不让你过
set global validate_password_policy=0;
# 设置密码校验长度,要不密码太短不让你过
set global validate_password_length=4;
# 这密码有够LOW了,但我就是想要
set password = password("1234");
# 可以退出,试试用新密码重新登录
quit
1234567891011121314151617
6. 配置my.cnf
# 打开配置文件
vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# 因为是本地测试环境,所以库能用就好了,我就不详细说明了(下篇在详细说明),大家可以参照下方官方建议去配置
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# 另外列举下vi编辑器命令
# i(按i键进入INSERT模式,可开始编辑)
# Esc(退出编辑模式)
# :wq(保存退出)
# :q(退出)
# :q!(不保存强制退出)
# 重启服务生效(另需注意:配置内路径需要自行创建目录及赋予权限)
systemctl restart mysqld
123456789101112131415161718192021222324252627282930313233343536373839404142
7. 配置远程连接
# 用新密码登进去试试
mysql -uroot -p
# 授权 所有权限(all),所有数据库(*.*) 给 用户名(root),任何主机(%),密码(yourpassword)
grant all privileges on *.* to 'root'@'%' identified by 'yourpassword' with grant option;
# 刷新权限使其立即生效
flush privileges;
# 退出MySQL
quit
# 关闭防火墙
systemctl stop firewalld
1234567891011
至此,我在外面用Navicat等可视化工具就可以远程连接数据库了,可劲造吧。。。
🐞标题:CentOS7通过rpm安装MySQL5.7.30
👽作者:ruige
🐾地址:https://jjdhhc.com/articles/2020/11/07/1604714238949.html
🙏感恩:谢谢您的打赏与支持!中间图片是我的微信公众号,扫码关注哦!