Java教程

2021-04-12

本文主要是介绍2021-04-12,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

MySQL在linux中的源码安装,特详细看了一定可以学会

https://blog.csdn.net/weixin_46049759/article/details/115312723?utm_source=app&app_version=4.5.7

yum的安装

因为本次安装需要用到yum,如果没有安装yum则需要先安装yum,一下为yum的安装步骤(我用的是redhat8的安装不同版本的安装可以有些许不同)
1.用vim指令进入到 /etc/yum.repos.d/redhat.repo修改内部文件

vim /etc/yum.repos.d/redhat.repo

在进入之后先按i键进入修改模式,然后将里面原本的所有内容删除,复制下面的代码,然后按下esc键退出编辑模式按下“:”并输入“:wq!”保存退出。

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#
 
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
        http://mirrors.aliyuncs.com/centos/$releasever/BaseOS/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/os/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/os/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
 
[PowerTools]
name=CentOS-$releasever - PowerTools - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/PowerTools/$basearch/os/
        http://mirrors.aliyuncs.com/centos/$releasever/PowerTools/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/PowerTools/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official


[AppStream]
name=CentOS-$releasever - AppStream - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/
        http://mirrors.aliyuncs.com/centos/$releasever/AppStream/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/AppStream/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

2.执行完上诉操作之后,输入以下代码

yum clean all
yum makecache
yum repolist

如果没有报错则yum安装成功,如果报错了可能是因为我们的版本不同,可以在博客上查看其他大佬的作品进行yum的安装。

MySQL安装包的获取

下载网站:[https://downloads.mysql.com/archives/community/]
进入网页之后可以看到如下界面
在这里插入图片描述
这里以5.7.14版本为例
在这里插入图片描述
点击download之后选择Save File 选择OK即可在这里插入图片描述

2.将文件移动到指定位置

先创建一个文件夹来存放这个安装包
具体代码为:mkdir /soft (这个soft可以根据自己的喜好来定义,如果出现’cannot create directory’则证明没有切换到root用户,可以用 'su root’指令切换)具体操作如下:

在这里插入图片描述

切换到根目录下输入指令’ll’可以发现文件已经创建.
在这里插入图片描述
接着将文件移动到’/soft’
一般通过浏览器下载的文件会home目录下的此用户的Downloads文件下
例如我的文件的位置便是:’/home/conan/Downloads’
通过下面的指令我们可以看见mysql的安装包确实在该目录下.
在这里插入图片描述
然后我们使用 sudo mv 指令将mysql-boost-5.7.14.tar.gz移动到soft

 sudo mv /home/conan/Downloads/mysql-boost-5.7.14.tar.gz  /soft

我们可以通过指令查看确实已经移动到了’/soft’
在这里插入图片描述
确实将mysql-boost-5.7.14.tar.gz移动到目录之后进入下一步;

软件的安装

1.先输入代码:

dhclient

2.进行MySQL使用的必要工具的安装

yum install -y cmake gcc-c++* make ncurses-devel
yum install libaio libaio-devel openssl-devel -y
yum install perl-Data-Dumper -y
yum install net-tools vim -y

3.进行软件的解压,个人习惯的缘故我更喜欢先把文件移动到指定位置,再在该位置直接解压到当前文件夹所以我先将文件移动到了 /usr/local/src/ 具体请查看以下命令:

sudo mv /soft/mysql-boost-5.7.14.tar.gz  /usr/local/src/
cd /usr/local/src/
tar xf mysql-boost-5.7.14.tar.gz

4.替MySQL创建用户和组

groupadd -r -g 306 mysql
useradd -g 306 -r -u 306 mysql

5.cmake MySQL的数据库
先进入到解压好的MySQL目录

cd /usr/local/src/mysql-5.7.14/

进入到解压目录之后执行以下代码:

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL-USER=mysql -DDOWNLOAD_BOOST=1 -DWITH_BOOST=./boost

再执行下面的命令

make -j 4 && make install

这里等待时间可能比较久
6.更改文件夹属主和属组

chown -R mysql.mysql /usr/local/mysql/

7.初始化MySQL

/usr/local/mysql/bin/mysqld --initialize \
--user=mysql --datadir=/usr/local/mysql/data \
--basedir=/usr/local/mysql/

8.为mysql提供主配置文件

cd /usr/local/mysql/
\cp support-files/my-default.cnf /etc/my.cnf
vim /etc/my.cnf

更改成下述即可(可复制)

[root@localhost ~]# vim /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
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]
datadir = usr/local/mysql/data

9.为mysql提供sysv服务脚本

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld  --添加为系统服务
chkconfig mysqld on     --添加为系统服务

10.修改PATH环境变量,让系统可以直接使用mysql的相关命令

vim /etc/profile.d/mysql.sh

在其中插入export PATH=$PATH:/usr/local/mysql/bin即可
11.启动MySQL

systemctl start mysqld
这篇关于2021-04-12的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!