首页 > 数据库 >在VMware已安装的CentOS7.9上编译安装mysql5.6

在VMware已安装的CentOS7.9上编译安装mysql5.6

时间:2024-11-10 21:30:37浏览次数:1  
标签:application mysql root mysql5.6 devel CentOS7.9 64 MySQL 安装

VMware已安装的CentOS7.9上编译安装mysql5.6

目录

  • 1、安装依赖
  • 2、下载MySQL源码
  • 3、解压源码包
  • 4、编译MySQL
    • 4.1、编译前,cmake生成Makefile
    • 4.2、编译MySQL
  • 5、安装MySQL
  • 6、配置MySQL
    • 6.1、创建MySQL的用户和组
    • 6.2、创建数据目录并设置权限
    • 6.3、初始化MySQL数据库
  • 7、启动MySQL
  • 8、安全配置

准备工作:VMware已安装好CentOS7.9。VMware安装CentOS7.9可以参考唐浩荣的博客:在VMware中安装CentOS7(超详细的图文教程)

本博客使用到的镜像站:阿里云官方镜像站https://developer.aliyun.com/mirror/

CentOS7.9.2009源:CentOS-7-x86_64-Everything-2009.iso

MySQL5.6.51源:mysql-5.6.51.tar.gz

为了后续的主从复制等操作,制作了VMware安装的3个虚拟机实例,虚拟机设置内存大于等于4G,cpu至少2核以上。

| IP地址 | 虚拟机名称 | 账号 |
| 192.168.58.159 | CentOS7_Master1 |root |
| 192.168.58.160 | CentOS7_Slave1 | root |
| 192.168.58.161 | CentOS7_Slave2 | root |

Selinux及防火墙的关闭,编译安装mysql5.6无需Selinux及防火墙关闭,对于初学者的我,不太会设置策略,所以先关闭,之后再开。

# 先查看selinux的情况
getenforce

# 设置selinux为disabled
sudo vi /etc/selinux/config
SELINUX=disabled

# 重启生效
reboot

# 重启后再看状态
getenforce

禁用前selinux情况

selinux禁用前配置:

selinux禁用后配置:

确认结果:

# 关闭防火墙
firewall-cmd --state
systemctl stop firewalld
systemctl disable firewalld
firewall-cmd --state

防火墙关闭前情况

防火墙关闭及关闭后的情况

回到顶部

1、安装依赖

首先,配置下其他源:

CentOS 7的官方维护已于2024年6月30日正式结束,所以,生产环境需要使用其他操作系统,这里用CentOS 7做实验,要安装依赖包,需要修改下相关的镜像源。

配置方法见Alibaba,https://developer.aliyun.com/mirror/centos-vault

建议先备份 /etc/yum.repos.d/ 内的文件。

需要确定您所需要的小版本,如无特殊需要则使用该大版本的最后一个小版本,比如 6.10,5.11,我们将其标记为 $minorver,需要您在之后的命令中替换。

然后编辑 /etc/yum.repos.d/ 中的相应文件,在 mirrorlist= 开头行前面加 # 注释掉;并将 baseurl= 开头行取消注释(如果被注释的话)。 对于 CentOS 8 之前的版本,请把该行内的域名及路径(例如mirror.centos.org/centos/$releasever)替换为 mirrors.aliyun.com/centos-vault/$minorver。 对于 CentOS 8 ,请注意域名及路径发生了更换,此时需要替换的字段为 http://mirror.centos.org/$contentdir/$releasever

以上步骤可以被下方的命令完成

#  Centos 7
minorver=7.9.2009
sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \
         -e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=https://mirrors.aliyun.com/centos-vault/$minorver|g" \
         -i.bak \
         /etc/yum.repos.d/CentOS-*.repo
                 
# CentOS 8 
minorver=8.5.2111
sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \
         -e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=https://mirrors.aliyun.com/centos-vault/$minorver|g" \
         -i.bak \
         /etc/yum.repos.d/CentOS-*.repo

在编译前,要安装一些必要的依赖包:

# 安装依赖包,视实际情况而定
sudo yum install -y gcc gcc-c++ ncurses-devel perl perl-devel readline-devel bison bison-devel bison-libs bison-doc libaio libaio-devel libselinux libselinux-devel libsepol libsepol-devel libselinux-python openldap openldap-devel numactl numactl-devel pam pam-devel openssl-devel wget
cmake net-tools -y

# 查看已安装依赖包的版本
rpm -p gcc gcc-c++ ncurses-devel perl perl-devel readline-devel bison bison-devel bison-libs bison-doc libaio libaio-devel libselinux libselinux-devel libsepol libsepol-devel libselinux-python openldap openldap-devel numactl numactl-devel pam pam-devel openssl-devel cmake wget cmake net-tools

# 结果
gcc-4.8.5-44.el7.x86_64
gcc-c++-4.8.5-44.el7.x86_64
ncurses-devel-5.9-14.20130511.el7_4.x86_64
perl-5.16.3-299.el7_9.x86_64
readline-devel-6.2-11.el7.x86_64
bison-3.0.4-2.el7.x86_64
bison-devel-3.0.4-2.el7.x86_64
package bison-libs is not installed
package bison-doc is not installed
libaio-0.3.109-13.el7.x86_64
libaio-devel-0.3.109-13.el7.x86_64
libselinux-2.5-15.el7.x86_64
libselinux-devel-2.5-15.el7.x86_64
libsepol-2.5-10.el7.x86_64
libsepol-devel-2.5-10.el7.x86_64
libselinux-python-2.5-15.el7.x86_64
openldap-2.4.44-25.el7_9.x86_64
openldap-devel-2.4.44-25.el7_9.x86_64
numactl-2.0.12-5.el7.x86_64
numactl-devel-2.0.12-5.el7.x86_64
pam-1.1.8-23.el7.x86_64
pam-devel-1.1.8-23.el7.x86_64
openssl-devel-1.0.2k-26.el7_9.x86_64
wget-1.14-18.el7_6.1.x86_64
cmake-2.8.12.2-2.el7.x86_64

2、下载MySQL源码

# 将所有外部工具都放在新的文件夹下面
mkdir -p /home/brian/tools/

cd /home/brian/tools/

# 下载MySQL源码到上述文件夹下,aliyun源下载的更快一些
wget https://mirrors.aliyun.com/mysql/MySQL-5.6/mysql-5.6.51.tar.gz
#wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.51.tar.gz
#wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.51.tar.gz

3. 解压源码包

解压下载的源码包:

tar -zxvf mysql-5.6.51.tar.gz
cd mysql-5.6.51

4. 编译MySQL

在编译之前,建议使用cmake来生成Makefile

  cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.51 \
  -DCMAKE_CXX_FLAGS="-std=c++11" \
  -DMYSQL_DATADIR=/application/mysql-5.6.51/data \
  -DMYSQL_UNIX_ADDR=/application/mysql-5.6.51/tmp/mysql.sock \
  -DDEFAULT_CHARSET=utf8 \
  -DDEFAULT_COLLATION=utf8_general_ci \
  -DWITH_EXTRA_CHARSETS=all \
  -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  -DWITH_FEDERATED_STORAGE_ENGINE=1 \
  -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
  -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
  -DWITH_ZLIB=bundled \
  -DWITH_SSL=system \
  -DENABLED_LOCAL_INFILE=1 \
  -DWITH_EMBEDDED_SERVER=1 \
  -DENABLE_DOWNLOADS=1 \
  -DWITH_DEBUG=0

要看到以下两项都完成才行。

-- Configuring done
-- Generating done

如果有error,碰到什么就处理什么,第一步安装依赖那么多,就是为了避免在本环节出现因缺少依赖包导致的很多错误。

然后编译MySQL:

make

make需要达到100%才行,需要花费些时间。

5. 安装MySQL

编译完成后,安装MySQL:

sudo make install

cd /home/brian/tools/
ls /application/
cd /application/
# 验证mysql安装成功
# 创建软链接
ln -s /application/mysql-5.6.51/ /application/mysql

# 创建链接后,您可以使用 ls -l 命令来检查链接是否正确创建:
ls -l /application/mysql/

6. 配置MySQL

创建MySQL的用户和组:

# 创建mysql用户,用于授权目录
useradd -s /sbin/nologin -M mysql

# 验证是否创建了账号
id mysql

创建数据目录并设置权限:

sudo mkdir -p /application/mysql/tmp
sudo chown -R mysql:mysql /application/mysql/

数据库目前还无数据,需要做初始化

初始化MySQL数据库:

/application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data --user=mysql

# 问题Data::Dumper未安装
[root@centos7_master1 scripts]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data --user=mysql
FATAL ERROR: please install the following Perl modules before executing /application/mysql/scripts/mysql_install_db:
Data::Dumper

#出现上述问题,需安装Dumper
sudo yum install -y perl perl-devel
sudo yum install -y perl-CPAN 
cpan Data::Dumper


# 安装DUMPER过程中需要注意的
[root@centos7_slave2 scripts]# cpan Data::Dumper
Sorry, we have to rerun the configuration dialog for CPAN.pm due to
some missing parameters. Configuration will be written to
 <</root/.cpan/CPAN/MyConfig.pm>>


CPAN.pm requires configuration, but most of it can be done automatically.
If you answer 'no' below, you will enter an interactive dialog for each
configuration option instead.

Would you like to configure as much as possible automatically? [yes] yes

 <install_help>

Warning: You do not have write permission for Perl library directories.

To install modules, you need to configure a local Perl library directory or
escalate your privileges.  CPAN can help you by bootstrapping the local::lib
module or by configuring itself to use 'sudo' (if available).  You may also
resolve this problem manually if you need to customize your setup.

What approach do you want?  (Choose 'local::lib', 'sudo' or 'manual')
 [local::lib] local::lib
Would you like me to automatically choose some CPAN mirror
sites for you? (This means connecting to the Internet) [yes] yes
Would you like me to append that to /root/.bashrc now? [yes] yes

安装Data:Dumper成功

初始化成功

7. 启动MySQL

启动MySQL服务:

# 使用MySQL自动化生成的管理脚本
[root@centos7_master1 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@centos7_master1 mysql]# chmod 700 /etc/init.d/mysqld

# 提前准备好MySQL的my.conf
[root@centos7_master1 mysql]# cp support-files/my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? yes


# 启动MySQL服务
[root@centos7_master1 mysql]# /etc/init.d/mysqld start

# 问题1:欠缺文件夹
Starting MySQL.Logging to '/application/mysql-5.6.51/data/centos7_master1.err'.
241111 03:23:42 mysqld_safe Directory '/application/mysql-5.6.51/tmp' for UNIX socket file don't exists.
 ERROR! The server quit without updating PID file (/application/mysql-5.6.51/data/centos7_master1.pid).
[root@centos7_master1 mysql]#

# 问题1解决:创建/application/mysql-5.6.51/tmp文件夹
[root@centos7_master1 mysql]# mkdir -p /application/mysql/tmp

# 问题2:文件的权限归属问题
[root@centos7_master1 mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/application/mysql-5.6.51/data/centos7_master1.err'.
.. ERROR! The server quit without updating PID file (/application/mysql-5.6.51/data/centos7_master1.pid).

# 问题2解决:文件的权限归属mysql账号
[root@centos7_master1 mysql]# chown -R mysql.mysql /application/mysql/

# 成功启动MySQL服务
[root@centos7_master1 mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@centos7_master1 mysql]# netstat -tunlp|grep mysql
tcp6       0      0 :::3306                 :::*                    LISTEN      86789/mysqld

# 问题3:PATH变量还未修改
[root@centos7_master1 mysql]# mysql -uroot -p
-bash: mysql: command not found
[root@centos7_master1 mysql]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

# 问题3解决
[root@centos7_master1 mysql]# vi /etc/profile
# 到最后加入下面语句
# 写入PATH,加入MySQL的路径
export PATH=/application/mysql/bin:$PATH

# source生效
[root@centos7_master1 mysql]#source /etc/profile

# 正常登录mysql
[root@centos7_master1 mysql]# echo $PATH
/root/perl5/bin:/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@centos7_master1 mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.51 Source distribution

Copyright (c) 2000, 2021, 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>

问题2出现的原因,文件的权限归属问题

问题2解决后:

8. 安全配置

运行安全脚本:

[root@centos7_master1 scripts]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!




All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


Cleaning up...

按照提示设置root密码,移除匿名用户,禁止root用户远程登录等。

标签:application,mysql,root,mysql5.6,devel,CentOS7.9,64,MySQL,安装
From: https://www.cnblogs.com/barnett277/p/18537623

相关文章

  • MySQL数据库:本地部署数据库以及安装彩虹猫【Navicat】的安装
    文章目录一.安装前准备工作1.下载并解压文件2.修复电脑缺失的文件二.本地部署MySQL1.先解压`mysql-8.0.25-winx64.zip`,并把文件放到安装需要的位置,再把`my.ini`文件放到`mysql-8.0.25-winx64`的根目录2.修改注册表的根目录信息为自己的安装装路径3.进命令符执行`盘符+:`......
  • PostgreSQL 安装 POSTGRES_FDW
    PostgreSQL安装POSTGRES_FDW插件postgres_fdw模块提供外部数据包装器postgres_fdw它可以用于访问存储在外部PostgreSQL服务器中的数据。使用postgres_fdw访问外部数据需要做以下几点准备:1、使用CREATEextension安装postgres_fdw扩展2、使用createserver......
  • 通过官网下载Qt以及安装选择
    Qt是一个跨平台的应用开发框架,广泛用于桌面、移动、嵌入式和物联网应用的开发。它的主要作用包括:①跨平台支持:编写一次代码,可以在Windows、macOS、Linux、Android和iOS等多个平台上运行。②丰富的GUI组件:提供多种UI组件和工具,帮助快速构建现代化的用户界面。③扩展性......
  • %windir% 是一个环境变量,它指向当前操作系统中 Windows 安装目录的路径。它常用于批处
    %windir%是一个环境变量,它指向当前操作系统中Windows安装目录的路径。它常用于批处理文件、命令行或者脚本中,帮助系统或用户快速定位Windows系统文件夹的路径。类似的环境变量还有很多,它们通常用于在操作系统中快速访问重要的文件夹和目录,避免硬编码路径,从而提高脚本的可移植......
  • d2l安装教程
    安装Miniconda/Anaconda:创建一个新的环境,例如名为d2l的环境,并激活这个环境。condacreate--named2lpython=3.9-ycondaactivated2l安装深度学习框架和d2l软件包:在安装深度学习框架之前,请检查计算机上是否有可用的GPU。如果没有GPU,可以安装CPU版本。对于MXNet的GPU版本,需要......
  • centos 下安装部署ansible
    centos下安装部署ansibleansible2.2服务节点:192.168.211.133客户端1:192.168.211.139客户端2:192.168.211.140第一步:设置EPEL仓库Ansible仓库默认不在yum仓库中,因此我们需要使用下面的命令启用epel仓库1.下载epel库http://dl.fedoraproject.org/pub/epel/7/x86_64/e/......
  • Nodejs安装配置
    Nodejs安装配置安装:官方地址点击跳转:Node.js—在任何地方运行JavaScript安装到D盘(C盘外)Next即可配置在安装目录下,新建node_cachenode_global两个文件夹添加到环境变量:可以不用%NODE_HOME%的方式,添加直接添加D:\nodejs\node_cacheD:\nodejs\node_gl......
  • 【Mplus 8.7软件下载与安装教程】
     1、安装包Mplus8.7:链接:https://pan.quark.cn/s/128e81c51dbe提取码:1X7BMplus8.3:链接:https://pan.quark.cn/s/5ea5ff583480提取码:VdjtMplus7.4:链接:https://pan.quark.cn/s/414ec0c8cb14提取码:8jhm2、安装教程1)       双击Mplus8.7Demo(64-bit).msi安装......
  • AI绘画(Stable Diffusion)喂饭级教程(附安装包)
    AI绘画(StableDiffusion)喂饭级教程2022年8月,一款叫StableDiffusion的AI绘画软件开源发布,从此开启了AIGC在图像上的爆火发展时期一年后的今天,率先学会SD的人,已经挖掘出了越来越多AI绘画有趣的玩法从开始的AI美女、线稿上色、真人漫改、头像壁纸到后来的AI创意字、AI艺......
  • 【AE2024】专业视频后期制作软件下载安装(附百度云链接)
    目录AdobeAfterEffects软件简介1.软件功能介绍1.1动画与合成1.2视觉效果1.3动态图形与模板2.系统要求2.1操作系统2.2硬件要求2.3显示与分辨率3.使用场景3.1影视后期制作3.2广告与宣传片3.3动画与艺术创作AdobeAfterEffects软件简介AdobeAf......