centos7通过rpm-bundle方式安装mysql5.7.35
安装mysql时,每次去网上找安装步骤,质量参差不齐,还费时费力,索性将本次安装过程记录下来,方便以后参考查看。
准备材料:mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar
1.先卸载系统自带的mariadb
查找命令:
rpm -qa | grep -i mariadb
然后根据查找出的列表分别进行卸载,命令为:
rpm -e --nodeps ******
2.解压bundle.tar
注意先要建立一个文件夹再解压:(mkdir ./mysql)
tar xvf mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar -C ./mysql
3.安装mysql
解压后,按如下顺序进行安装:
rpm -ivh mysql-community-common-5.7.35-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.35-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-compat-5.7.35-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.35-1.el7.x86_64.rpm
注意:单纯安装mysql,devel组件可不安装,但是如果涉及使用python-devel组件及python访问mysql的相关组件,则需要安装:mysql-community-devel-5.7.35-1.el7.x86_64.rpm,否则会报错:
Error: Package: 1:mariadb-devel-5.5.68-1.el7.x86_64 (os) Requires: mariadb-libs(x86-64) = 1:5.5.68-1.el7
实质就是缺少mysql-community-devel组件,导致有关python访问mysql的各种组件安装失败。
参考:python实践学习之《问题:centos7安装mysql-devel出现包依赖问题》,特此感谢!
本次安装到server时,报错(如不报错,请跳过):
error: Failed dependencies: libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.35-1.el7.x86_64 libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.35-1.el7.x86_64 libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.35-1.el7.x86_64
则通过如下命令安装依赖项:libnuma
yum install numactl
4.mysql配置
安装完成后,启动mysql:
systemctl start mysqld.service
然后查找第一次启动时生成的临时密码:
grep 'temporary password' /var/log/mysqld.log:
输出如下所示:
2021-09-15T02:36:51.007047Z 1 [Note] A temporary password is generated for root@localhost: r/9kVoph#T+s
最后部分既是密码,使用root登录:
mysql -u root -p
登录后,使用show databases或者show tables时,系统均提示,先修改root密码,于是:
set password for root@localhost = password('******');
然后扩充root远程权限(其实是建立一个root@%账号),使之能远程连接:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '*****' flush privileges;
修改mysql默认的端口号:
vi /etc/my.cnf
在[mysqld]下建立一行:
port=****
重启mysql:
systemctl restart mysqld.service
查看本机端口监听情况:
netstat -lnpt
如果看到刚刚设定的端口处于listen状态即可。
然后打开系统防火墙特定端口,用于外部访问数据库:
firewall-cmd --zone=public --add-port=***/tcp --permanent
然后重启防火墙:
systemctl restart firewalld.service
至此,配置完成,从外网测试连接成功即可。