前言
最近想试水一下MYSQL的OCP考试,所以要准备一下MYSQL的测试环境。一般来说,mysql的安装方式有三种,rpm包、源码编译、二进制安装包,repo源安装其实也属于rpm包安装方式,现将我的安装过程整理如下:
环境准备与说明
外网连接:长城宽带200M
路由器内网地址:192.168.10.1
主机环境:Windows 10 企业版 LTSC
虚拟机软件:VMware® Workstation 16 Pro 16.1.0 build-17198959
镜像文件:CentOS7.6.ova ( 下载地址:https://pan.baidu.com/s/1tQzbz_qeGF0tht3vXh8RTg?pwd=artp )
安装过程
1 基本环境
导入CentOS7.6.ova,生成主机djtest,修改虚拟机设置(视情况修改):8G内存,2核CPU,网卡桥接,虚拟化引擎的3个选项都开启,开机。
控制台登录,用户root,密码123456
#修改主机名与IP
echo set nu>.vimrc
echo djtest>/etc/hostname
echo 192.168.10.48 djtest>>/etc/hosts
cat /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i.bak '/^IPA/ s/=.*/=192.168.10.48/;/^GATE/,/^DNS/ s/=.*/=192.168.10.1/' /etc/sysconfig/network-scripts/ifcfg-eth0
cat /etc/redhat-release
#CentOS Linux release 7.9.2009 (Core)
init 0
#快照 djtest_first_env
2 前期准备
启动,SSH工具登录djtest
#更换yum源及yum版本:
#卸载yum
yum version
rpm -qa|grep yum|xargs rpm -e --nodeps
#更新yum
cd /tmp && mkdir tt && cd tt
htpath='https://mirrors.aliyun.com/centos/7/os/x86_64/Packages'
#htpath='http://mirrors.163.com/centos/7/os/x86_64/Packages/'
wget $htpath/yum-3.4.3-168.el7.centos.noarch.rpm
wget $htpath/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget $htpath/yum-utils-1.1.31-54.el7_8.noarch.rpm
wget $htpath/yum-updateonboot-1.1.31-54.el7_8.noarch.rpm
wget $htpath/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
wget $htpath/rpm-4.11.3-45.el7.x86_64.rpm
wget $htpath/python-urlgrabber-3.10-10.el7.noarch.rpm
wget $htpath/python-kitchen-1.1.1-5.el7.noarch.rpm
wget $htpath/python-chardet-2.2.1-3.el7.noarch.rpm
unset htpath
rpm -Uvh rpm-.*.rpm --nodeps
rpm -Uvh python-*.rpm --nodeps
rpm -ivh yum-* --force --nodeps
cd /etc/yum.repos.d && mkdir -pv bk && mv -vf *.repo bk
rm -rf /tmp/tt
#版本查看
yum version
#更换repo为aliyun源
wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
sed -i 's#\$releasever#7#g' /etc/yum.repos.d/CentOS-Base.repo
#去除提示Warning: RPMDB altered outside of yum.
rm -rf /var/lib/yum/history/*.sqlite
#缓存加速
yum clean all && yum makecache fast
#系统更新
yum -y update
#安装killall所需要的工具包
yum -y install psmisc
#确认一下防火墙和selinux状态
systemctl status firewalld
getenforce
#快照 before_mysql_ins
3a repo安装mysql
#卸载系统中可能预安装的版本
rpm -qa|grep mysql|xargs rpm -e --nodeps
rpm -qa|grep mariadb|xargs rpm -e --nodeps
cat>/etc/yum.repos.d/mysql-community.repo<<EOF
# 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/x86_64
#更换为国内源:
baseurl=http://mirrors.ustc.edu.cn/mysql-repo/yum/mysql-5.7-community/el/7/x86_64
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
EOF
yum repolist all|grep mysql
yum install mysql-community-server -y
3b ==rpm方式安装
#官方或镜像站点下载后再上传也可以,效果是同样的
cd /tmp
htpath='https://mirrors.cloud.tencent.com/mysql/yum/mysql-5.7-community-el7-x86_64/'
wget $htpath/mysql-community-server-5.7.33-1.el7.x86_64.rpm
wget $htpath/mysql-community-client-5.7.33-1.el7.x86_64.rpm
wget $htpath/mysql-community-libs-5.7.33-1.el7.x86_64.rpm
wget $htpath/mysql-community-libs-compat-5.7.33-1.el7.x86_64.rpm
wget $htpath/mysql-community-common-5.7.33-1.el7.x86_64.rpm
unset htpath
yum -y localinstall my*.rpm
4 mysql简单测试
#快照 before_mysql_setup
mysqld --version
#mysqld Ver 5.7.33 for Linux on x86_64 (MySQL Community Server (GPL))
cat /etc/my.cnf
ls /var/lib/mysql
#无密码初始化数据库 不安全 以后再设置密码
mysqld --initialize-insecure
ls /var/lib/mysql
#避免错误提示
sed -i.bak '/^datadir=/ a explicit_defaults_for_timestamp=1' /etc/my.cnf
#启动
mysqld -uroot &
#登录测试
mysql
show databases;
quit
#关闭
mysqladmin -S /var/lib/mysql/mysql.sock shutdown
init 0
完结 PS
大概看了下,此方式安装的mysql 5.7.33中,没有mysqld_safe脚本程序,和二进制安装包还是有点区别,之后的详细配置修改等要视具体情况而定,再说。BYE
最后修改时间:2022-11-11 14:28:19
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




