这篇文章主要讲解了“Linux怎么用源码安装MySQL 5.7”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Linux怎么用源码安装MySQL 5.7”吧!


有两种方法来使用源码安装MySQL:
.使用一种标准的MySQL源码安装。标准的可用源码文件被压缩成tar文件,zip文件或RPM包。文件名的格式为mysql-version.tar.gz,mysql-version.zip或mysql-version.rpm。其中version是版本号比例如5.7.25。发布的源码文件名与预先编译好的二进制文件名是有区别的,源码文件名通常不包含平台名,而二进制文件名包含平台名,例如pc-linux-i686或winx64。

.使用MySQL开发树。如何构建开发树将在使用开发源码树来安装MySQL中进行介绍。

使用源码安装MySQL操作系统所要满足的条件
使用源码来安装MySQL需要几个开发工具。无论您使用的是标准的源代码分发版还是开发源代码树,都需要这些工具中的一部分。是否需要其它工具依赖于你的安装方法。

为了使用源码来安装MySQL,不管使用何种安装方法下面的要求必须要满足:
.CMake,用来在所有平台上构建框架,可以从http://www.cmake.org来下载CMake。

.一个好的make程序,虽然一些平台有它们自己的make实现,但强烈建议使用GNU make 3.75或更高版本。它可能已经存在于你的系统中了gmake。可以从http://www.gnu.org/software/make/下载GNU make。

.ANSI C++编译器。可以对force_unsupported_compiler的描述。

.为了构建MySQL需要Boost C++库(但不使用它)。Boost 1.59.0必须被安装。为了获得Boost与它的安装指令,可以访问https://www.boost.org/网址。在Boost安装后,当调用CMake时通过使用WITH_BOOST选项来告诉构建系统在哪里定位Boost文件。

shell>cmake.-DWITH_BOOST=/usr/local/boost_1_59_0

根据实际情况来调整路径。

.ncurses库 https://www.gnu.org/software/ncurses/ncurses.html

.足够的空闲内存。当编译很大的源文件时如果遇到了"internal compiler error"错误,那么可能是因为你没有足够的内存。如果在一个虚拟机上进行编译,尝试增加内存分配。

.如果你希望运行测试脚本那么就需要安装perl。大多数像Unix的系统已经包含了perl。在windows上可以使用ActiveState Perl。

为了使用标准的源码发布版本来安装MySQL,需要以下一种工具来解压发布的源码文件:
.对于一个.tar.gz的压缩tar文件,GNU gunzip可以用来解压tar用来unpack。如果你的tar程序支持z选项,它可以用来解压与 unpack文件。GNU tar众所周知是有效的。一些操作系统提供的标准tar不能对MySQL发布版本的长文件名进行unpack操作。你应该安装GUN tar或者可能的话,使用预安装版本的GNU tar。常用的有gnutar,gtar,tar或者自由软件目录,比如/usr/sfw/bin或/usr/local/bin。GNU tar可以从http://www.gnu.org/software/tar/进行下载。

.对于一个.zip归档文件,winzip或另外的工具可以读取.zip文件。

.对于一个.rpm的RPM包,rpmbuild程序用来对构建的发布版本进行unpack操作。

为了使用开发源码树来安装MySQL,需要安装以下额外的工具:
.需要Git版本控制系统来获得开发源代码。https://help.github.com/en提供了指令在不同平台上下载与安装Git。MySQL官方组织已经于2014年9月加入了GitHub。

.bison 2.1或更高版本,可以从http://www.gnu.org/software/bison/网址进行下载(1版本不再支持),尽可能的使用最新版本,如果你遇到了问题,那么升级到最新的版本,而不是回退到更早的版本。

bison可以从http://www.gnu.org/software/bison/网址进行下载,对于Windows平台可以从http://gnuwin32.sourceforge.net/packages/bison.htm网址进行下载。在Windows平台上,bison的缺省目录是C:\Program Files\GnuWin32目录。有一些工具可以在查找bison会失败,因为在目录名中存在空隔。同样,Visual Studio如果在路径中存在空隔可能会出现hang住。为了解决这种问题的出现,可以将bison安装到C:\GnuWin32目录。

.在Solaris平台上,除了bison之外m4必须被安装。m4可以从http://www.gnu.org/software/m4/网址下载。

注意在安装任何程序之后,需要修改你的PATH环境变量来包含定位程序的目录。

源码安装MySQL的布局
缺省情况下,当使用源码编译后安装MySQL,安装操作会将文件安装在/usr/local/mysql目录中。这与使用二进制文件安装的安装目录是一样的。

使用标准源码安装MySQL
1.安装所需要的工具包

[root@localhost~]#yum-yinstallgcc*gcc-c++ncurses*ncurses-devel*cmake*bison*libgcrypt*perl*make*.......已安装:gcc-gnat.x86_640:4.8.5-36.0.1.el7gcc-objc.x86_640:4.8.5-36.0.1.el7gcc-objc++.x86_640:4.8.5-36.0.1.el7libgcrypt-devel.x86_640:1.5.3-14.el7ncurses-devel.x86_640:5.9-14.20130511.el7_4ncurses-term.noarch0:5.9-14.20130511.el7_4perl-Algorithm-Diff.noarch0:1.1902-17.el7perl-App-cpanminus.noarch0:1.6922-2.el7perl-Archive-Extract.noarch1:0.68-3.el7perl-Archive-Zip.noarch0:1.30-11.el7perl-Authen-SASL.noarch0:2.15-10.el7perl-B-Lint.noarch0:1.17-3.el7perl-Bit-Vector.x86_640:7.3-3.el7perl-CGI.noarch0:3.63-4.el7perl-CGI-Session.noarch0:4.35-16.el7perl-CPAN.noarch0:1.9800-293.el7perl-CPAN-Meta.noarch0:2.120921-5.el7perl-CPAN-Meta-Requirements.noarch0:2.122-7.el7perl-CPAN-Meta-YAML.noarch0:0.008-14.el7perl-CPANPLUS.noarch0:0.91.38-4.el7perl-CPANPLUS-Dist-Build.noarch0:0.70-3.el7perl-Carp-Clan.noarch0:6.04-10.el7perl-Class-ISA.noarch0:0.36-1010.el7perl-Class-Load.noarch0:0.20-3.el7perl-Class-Singleton.noarch0:1.4-14.el7perl-Convert-ASN1.noarch0:0.26-4.el7perl-DBD-MySQL.x86_640:4.023-6.0.1.el7perl-DBD-Pg.x86_640:2.19.3-4.el7perl-DBIx-Simple.noarch0:1.35-7.el7perl-Data-OptList.noarch0:0.107-9.el7perl-Date-Calc.noarch0:6.3-14.el7perl-Date-Manip.noarch0:6.41-2.el7perl-DateTime.x86_642:1.04-6.el7perl-DateTime-Format-DateParse.noarch0:0.05-5.el7perl-DateTime-Locale.noarch0:0.45-6.el7perl-DateTime-TimeZone.noarch0:1.70-1.el7perl-Devel-Symdump.noarch1:2.10-2.el7perl-Digest-SHA1.x86_640:2.13-9.el7perl-Env.noarch0:1.04-2.el7perl-ExtUtils-CBuilder.noarch1:0.28.2.6-293.el7perl-ExtUtils-Embed.noarch0:1.30-293.el7perl-FCGI.x86_641:0.74-8.el7perl-File-CheckTree.noarch0:4.42-3.el7perl-File-Fetch.noarch0:0.42-2.el7perl-Font-AFM.noarch0:1.20-13.el7perl-FreezeThaw.noarch0:0.5001-10.el7perl-GD.x86_640:2.49-3.el7perl-GSSAPI.x86_640:0.28-9.el7perl-HTML-Format.noarch0:2.10-7.el7perl-HTML-Tree.noarch1:5.03-2.el7perl-IO-stringy.noarch0:2.110-22.el7perl-IPC-Cmd.noarch1:0.80-4.el7perl-JSON.noarch0:2.59-2.el7perl-JSON-PP.noarch0:2.27202-2.el7perl-LDAP.noarch1:0.56-6.el7perl-LWP-Protocol-https.noarch0:6.04-4.el7perl-List-MoreUtils.x86_640:0.33-9.el7perl-Locale-Codes.noarch0:3.26-2.el7perl-Locale-Maketext.noarch0:1.23-3.el7perl-Locale-Maketext-Simple.noarch1:0.21-293.el7perl-Log-Message.noarch1:0.08-3.el7perl-Log-Message-Simple.noarch0:0.10-2.el7perl-Module-Build.noarch2:0.40.05-2.el7perl-Module-CoreList.noarch1:2.76.02-293.el7perl-Module-Implementation.noarch0:0.06-6.el7perl-Module-Load.noarch1:0.24-3.el7perl-Module-Load-Conditional.noarch0:0.54-3.el7perl-Module-Loaded.noarch1:0.08-293.el7perl-Module-Metadata.noarch0:1.000018-2.el7perl-Module-Pluggable.noarch1:4.8-3.el7perl-Module-Runtime.noarch0:0.013-4.el7perl-Module-Signature.noarch0:0.73-2.el7perl-Mozilla-CA.noarch0:20130114-5.el7perl-Newt.x86_640:1.08-36.el7perl-Object-Accessor.noarch1:0.42-293.el7perl-PAR-Dist.noarch0:0.49-2.el7perl-Package-DeprecationManager.noarch0:0.13-7.el7perl-Package-Stash.noarch0:0.34-2.el7perl-Package-Stash-XS.x86_640:0.26-3.el7perl-Params-Check.noarch1:0.38-2.el7perl-Params-Util.x86_640:1.07-6.el7perl-Params-Validate.x86_640:1.08-4.el7perl-Parse-CPAN-Meta.noarch1:1.4404-5.el7perl-Perl-OSType.noarch0:1.003-3.el7perl-Perl4-CoreLibs.noarch0:0.003-7.el7perl-Pod-Checker.noarch0:1.60-2.el7perl-Pod-Coverage.noarch0:0.23-3.el7perl-Pod-LaTeX.noarch0:0.61-2.el7perl-Pod-Parser.noarch0:1.61-2.el7perl-Pod-Plainer.noarch0:1.03-4.el7perl-SGMLSpm.noarch0:1.03ii-31.el7perl-SNMP_Session.noarch0:1.13-5.el7perl-String-ShellQuote.noarch0:1.04-10.el7perl-Sub-Install.noarch0:0.926-6.el7perl-Sys-CPU.x86_640:0.54-4.el7perl-Sys-Guestfs.x86_641:1.38.2-12.0.1.el7perl-Sys-MemInfo.x86_640:0.91-7.el7perl-Sys-Virt.x86_640:4.5.0-2.el7perl-Term-UI.noarch0:0.36-2.el7perl-Test-Pod.noarch0:1.48-3.el7perl-Test-Pod-Coverage.noarch0:1.08-21.el7perl-Test-Simple.noarch0:0.98-243.el7perl-Text-Diff.noarch0:1.41-5.el7perl-Text-Soundex.x86_640:3.04-4.el7perl-Text-Unidecode.noarch0:0.04-20.el7perl-Time-Piece.x86_640:1.20.1-293.el7perl-Try-Tiny.noarch0:0.12-2.el7perl-Version-Requirements.noarch0:0.101022-244.el7perl-XML-Dumper.noarch0:0.81-17.el7perl-XML-Filter-BufferText.noarch0:1.01-17.el7perl-XML-Grove.noarch0:0.46alpha-52.el7perl-XML-SAX-Writer.noarch0:0.53-4.el7perl-XML-Twig.noarch0:3.44-2.el7perl-XML-Writer.noarch0:0.623-3.el7perl-XML-XPath.noarch0:1.13-22.el7perl-YAML.noarch0:0.84-5.el7perl-YAML-Tiny.noarch0:1.51-6.el7perl-autodie.noarch0:2.16-2.el7perl-core.x86_640:5.16.3-293.el7perl-gettext.x86_640:1.05-28.el7perl-homedir.noarch0:1.008010-4.el7perl-libintl.x86_640:1.20-12.el7perl-libxml-perl.noarch0:0.08-19.el7perl-local-lib.noarch0:1.008010-4.el7perltidy.noarch0:20121207-3.el7作为依赖被安装:glusterfs-cli.x86_640:3.12.2-18.el7glusterfs-client-xlators.x86_640:3.12.2-18.el7libgnat.x86_640:4.8.5-36.0.1.el7libgnat-devel.x86_640:4.8.5-36.0.1.el7libgpg-error-devel.x86_640:1.12-3.el7libobjc.x86_640:4.8.5-36.0.1.el7libvirt-bash-completion.x86_640:4.5.0-10.el7libvirt-daemon-driver-storage-core.x86_640:4.5.0-10.el7libvirt-daemon-driver-storage-disk.x86_640:4.5.0-10.el7libvirt-daemon-driver-storage-gluster.x86_640:4.5.0-10.el7libvirt-daemon-driver-storage-iscsi.x86_640:4.5.0-10.el7libvirt-daemon-driver-storage-logical.x86_640:4.5.0-10.el7libvirt-daemon-driver-storage-mpath.x86_640:4.5.0-10.el7libvirt-daemon-driver-storage-rbd.x86_640:4.5.0-10.el7libvirt-daemon-driver-storage-scsi.x86_640:4.5.0-10.el7libvirt-libs.x86_640:4.5.0-10.el7openjade.x86_640:1.3.2-45.el7opensp.x86_640:1.5.2-19.el7pcp-selinux.x86_640:4.1.0-4.el7postgresql-libs.x86_640:9.2.24-1.el7_5squashfs-tools.x86_640:4.3-0.21.gitaae0aff4.el7更新完毕:bison.x86_640:3.0.4-2.el7gcc.x86_640:4.8.5-36.0.1.el7gcc-c++.x86_640:4.8.5-36.0.1.el7gcc-gfortran.x86_640:4.8.5-36.0.1.el7libgcrypt.x86_640:1.5.3-14.el7make.x86_641:3.82-23.el7ncurses.x86_640:5.9-14.20130511.el7_4ncurses-base.noarch0:5.9-14.20130511.el7_4ncurses-libs.x86_640:5.9-14.20130511.el7_4perl.x86_644:5.16.3-293.el7perl-Digest-SHA.x86_641:5.85-4.el7perl-ExtUtils-Install.noarch0:1.58-293.el7perl-ExtUtils-ParseXS.noarch1:3.18-3.el7perl-Getopt-Long.noarch0:2.40-3.el7perl-Git.noarch0:1.8.3.1-19.el7perl-HTTP-Daemon.noarch0:6.01-8.el7perl-IO-Socket-IP.noarch0:0.21-5.el7perl-IO-Socket-SSL.noarch0:1.94-7.el7perl-IO-Zlib.noarch1:1.10-293.el7perl-Net-DNS.x86_640:0.72-6.el7perl-Net-SSLeay.x86_640:1.55-6.el7perl-PCP-PMDA.x86_640:4.1.0-4.el7perl-Package-Constants.noarch1:0.02-293.el7perl-Pod-Escapes.noarch1:1.04-293.el7perl-Socket.x86_640:2.010-4.el7perl-Test-Harness.noarch0:3.28-3.el7perl-devel.x86_644:5.16.3-293.el7perl-hivex.x86_640:1.3.10-6.9.el7perl-libs.x86_644:5.16.3-293.el7perl-macros.x86_644:5.16.3-293.el7perl-version.x86_643:0.99.07-3.el7作为依赖被升级:cpp.x86_640:4.8.5-36.0.1.el7git.x86_640:1.8.3.1-19.el7glusterfs.x86_640:3.12.2-18.el7glusterfs-api.x86_640:3.12.2-18.el7glusterfs-fuse.x86_640:3.12.2-18.el7glusterfs-libs.x86_640:3.12.2-18.el7glusterfs-rdma.x86_640:3.12.2-18.el7hivex.x86_640:1.3.10-6.9.el7libgcc.x86_640:4.8.5-36.0.1.el7libgfortran.x86_640:4.8.5-36.0.1.el7libgomp.x86_640:4.8.5-36.0.1.el7libguestfs.x86_641:1.38.2-12.0.1.el7libquadmath.x86_640:4.8.5-36.0.1.el7libquadmath-devel.x86_640:4.8.5-36.0.1.el7libstdc++.x86_640:4.8.5-36.0.1.el7libstdc++-devel.x86_640:4.8.5-36.0.1.el7libvirt.x86_640:4.5.0-10.el7libvirt-client.x86_640:4.5.0-10.el7libvirt-daemon.x86_640:4.5.0-10.el7libvirt-daemon-config-network.x86_640:4.5.0-10.el7libvirt-daemon-config-nwfilter.x86_640:4.5.0-10.el7libvirt-daemon-driver-interface.x86_640:4.5.0-10.el7libvirt-daemon-driver-lxc.x86_640:4.5.0-10.el7libvirt-daemon-driver-network.x86_640:4.5.0-10.el7libvirt-daemon-driver-nodedev.x86_640:4.5.0-10.el7libvirt-daemon-driver-nwfilter.x86_640:4.5.0-10.el7libvirt-daemon-driver-qemu.x86_640:4.5.0-10.el7libvirt-daemon-driver-secret.x86_640:4.5.0-10.el7libvirt-daemon-driver-storage.x86_640:4.5.0-10.el7libvirt-daemon-kvm.x86_640:4.5.0-10.el7openssl.x86_641:1.0.2k-16.0.1.el7openssl-libs.x86_641:1.0.2k-16.0.1.el7pcp.x86_640:4.1.0-4.el7pcp-conf.x86_640:4.1.0-4.el7pcp-libs.x86_640:4.1.0-4.el7python-pcp.x86_640:4.1.0-4.el7supermin5.x86_640:5.1.19-1.el7完毕!

2.使用命令检查是否安装有MySQL Server包

[root@localhost~]#rpm-qa|grepmysql[root@localhost~]#rpm-aq|grepmysqlmysql-community-libs-5.6.23-3.el7.x86_64qt-mysql-4.8.5-8.0.1.el7.x86_64akonadi-mysql-1.9.2-4.0.1.el7.x86_64mysql-community-common-5.6.23-3.el7.x86_64mysql-community-server-5.6.23-3.el7.x86_64mysql-community-client-5.6.23-3.el7.x86_64

删除操作有以下两种
rpm -e mysql-libs //普通删除模式
rpm -e --nodeps mysql-lib// 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除

[root@localhost~]#rpm-e--nodepsmysql-community-libs[root@localhost~]#rpm-e--nodepsakonadi-mysql[root@localhost~]#rpm-e--nodepsmysql-community-common[root@localhost~]#rpm-e--nodepsmysql-community-server[root@localhost~]#rpm-e--nodepsmysql-community-client[root@localhost~]#rpm-e--nodepsqt-mysql[root@localhost~]#rpm-aq|grepmysql

3.下载源码文件mysql-5.7.26.tar.gz并上传到服务器的/soft目录中

[root@localhostsoft]#ls-lrt总用量79960-rw-r--r--.1rootroot540568995月3016:36mysql-5.7.26.tar.gz

4.下载boost包并上传到服务器的/soft目录中

5. 创建mysql用户与用户组

[root@localhost/]#groupaddmysql[root@localhost/]#useradd-r-gmysql-s/bin/falsemysql

因为用户只用于所有权目的,而不是登录目的,useradd命令使用-r与-s /bin/false选项来创建一个用户没有登录服务器主机的权限。

6.创建并修改/mysqlsoft/mysql与/mysqldata/mysql目录权限

[root@localhost/]#mkdir-p/mysqlsoft/mysql[root@localhost/]#mkdir-p/mysqldata/mysql[root@localhost/]#chown-Rmysql:mysql/mysqlsoft[root@localhost/]#chown-Rmysql:mysql/mysqldata/mysql[root@localhost/]#chmod-R775/mysqlsoft/mysql[root@localhost/]#chmod-R775/mysqldata/mysql

7.解压boost软件包与MySQL源码包

[root@localhostsoft]#unzipboost_1_59_0.zip[root@localhostsoft]#ls-lrt总用量201556drwx------.8rootroot40968月122015boost_1_59_0-rw-r--r--.1rootroot540568995月3016:36mysql-5.7.26.tar.gz-rw-r--r--.1rootroot1245062596月1321:07boost_1_59_0.zip

将MySQL文件解压到/soft目录下

[root@localhostsoft]#tarzxvfmysql-5.7.26.tar.gz[root@localhostsoft]#ls-lrt总用量201560drwx------.8rootroot40968月122015boost_1_59_0drwxr-xr-x.3571613141540964月1321:46mysql-5.7.26-rw-r--r--.1rootroot540568995月3016:36mysql-5.7.26.tar.gz-rw-r--r--.1rootroot278169006月1011:32docker-17.03.0-ce.tgz-rw-r--r--.1rootroot1245062596月1321:07boost_1_59_0.zip总用量4[root@localhostsoft]#chown-Rmysql:mysqlmysql-5.7.26[root@localhostsoft]#chmod-R775mysql-5.7.26

8.预编译MySQL

[root@localhostsoft]#su-mysql上一次登录:一6月1712:21:54CST2019pts/0上-bash-4.2$cd/soft/mysql-5.7.26/-bash-4.2$cmake.-DCMAKE_INSTALL_PREFIX=/mysqlsoft/mysql\>-DMYSQL_DATADIR=/mysqldata/mysql\>-DMYSQL_UNIX_ADDR=/mysqlsoft/mysql/mysql.sock\>-DWITH_BOOST=../boost_1_59_0\>-DWITH_INNOBASE_STORAGE_ENGINE=1\>-DWITH_PARTITION_STORAGE_ENGINE=1\>-DWITH_FEDERATED_STORAGE_ENGINE=1\>-DWITH_BLACKHOLE_STORAGE_ENGINE=1\>-DWITH_MYISAM_STORAGE_ENGINE=1\>-DENABLED_LOCAL_INFILE=1\>-DENABLE_DTRACE=0\>-DDEFAULT_CHARSET=utf8mb4\>-DDEFAULT_COLLATION=utf8mb4_general_ci\>-DWITH_EMBEDDED_SERVER=1....................--FoundPkgConfig:/bin/pkg-config(foundversion"0.27.1")--checkingformodule'libtirpc'--package'libtirpc'notfound--PerformingTestHAVE_STRUCT_SOCKADDR_SA_LEN--PerformingTestHAVE_STRUCT_SOCKADDR_SA_LEN-Failed--PerformingTestHAVE_STRUCT_IFREQ_IFR_NAME--PerformingTestHAVE_STRUCT_IFREQ_IFR_NAME-Success--PerformingTestHAVE_XDR_OPS_X_PUTINT32--PerformingTestHAVE_XDR_OPS_X_PUTINT32-Success--PerformingTestHAVE_XDR_OPS_X_GETINT32--PerformingTestHAVE_XDR_OPS_X_GETINT32-Success--PerformingTestHAVE___CONST--PerformingTestHAVE___CONST-Success--PerformingTestHAVE_RPC_INLINE_T--PerformingTestHAVE_RPC_INLINE_T-Failed--PerformingTestOLD_XDR--PerformingTestOLD_XDR-Failed--PerformingTestX_GETPOSTN_NOT_USE_CONST--PerformingTestX_GETPOSTN_NOT_USE_CONST-Success--PerformingTestHAS_INCOMPATIBLE_POINTER_TYPES--PerformingTestHAS_INCOMPATIBLE_POINTER_TYPES-Failed--PerformingTestX_PUTLONG_NOT_USE_CONST--PerformingTestX_PUTLONG_NOT_USE_CONST-Failed--checkingformodule'libtirpc'--package'libtirpc'notfound--RPC_INCLUDE_DIRS/usr/include--UsingBoostheadersfrom/soft/boost_1_59_0--PerformingTestCXX_HAVE_SIGN_COMPARE--PerformingTestCXX_HAVE_SIGN_COMPARE-Success--PerformingTestCXX_HAVE_UNUSED_VARIABLE--PerformingTestCXX_HAVE_UNUSED_VARIABLE-Success--MYSQLX-Textlogofprotobufmessagesenabled--PerformingTestHAVE_UNUSED_PARAMETER--PerformingTestHAVE_UNUSED_PARAMETER-Success--Googletestwasnotfound.gtest-basedunittestswillbedisabled.Youcanruncmake.-DENABLE_DOWNLOADS=1toautomaticallydownloadandbuildrequiredcomponentsfromsource.--Ifyouareinsideafirewall,youmayneedtouseanhttpsproxy:exporthttps_proxy=http://example.com:80--PerformingTestHAVE_MISLEADING_INDENTATION--PerformingTestHAVE_MISLEADING_INDENTATION-Failed--executabletargetmysqlddebug_target/soft/debug/sql/mysqld--LibrarymysqlserverdependsonOSLIBS-lpthread;m;rt;crypt;dl--MERGE_CONVENIENCE_LIBRARIESTARGETmysqlserver--MERGE_CONVENIENCE_LIBRARIESLIBSdbug;strings;regex;mysys;mysys_ssl;vio;zlib;yassl;taocrypt;crypt;dl;archive_embedded;blackhole_embedded;csv_embedded;federated_embedded;heap_embedded;innobase_embedded;lz4_lib;myisam_embedded;myisammrg_embedded;partition_embedded;ngram_parser_embedded;sql_embedded--MERGE_CONVENIENCE_LIBRARIESMYLIBSdbug;strings;regex;mysys;mysys_ssl;vio;zlib;yassl;taocrypt;archive_embedded;blackhole_embedded;csv_embedded;federated_embedded;heap_embedded;innobase_embedded;lz4_lib;myisam_embedded;myisammrg_embedded;partition_embedded;ngram_parser_embedded;sql_embedded--librarytargetmysqlserverdebug_target/soft/debug/archive_output_directory/libmysqld.a--INSTALLmysqlclient.pclib/pkgconfig--Skippingdebpackagingonunsupportedplatform.--CMAKE_BUILD_TYPE:RelWithDebInfo--COMPILE_DEFINITIONS:_GNU_SOURCE;_FILE_OFFSET_BITS=64;HAVE_CONFIG_H;HAVE_LIBEVENT2--CMAKE_C_FLAGS:-Wall-Wextra-Wformat-security-Wvla-Wwrite-strings-Wdeclaration-after-statement--CMAKE_CXX_FLAGS:-Wall-Wextra-Wformat-security-Wvla-Woverloaded-virtual-Wno-unused-parameter--CMAKE_C_LINK_FLAGS:--CMAKE_CXX_LINK_FLAGS:--CMAKE_C_FLAGS_RELWITHDEBINFO:-O3-g-fabi-version=2-fno-omit-frame-pointer-fno-strict-aliasing-DDBUG_OFF--CMAKE_CXX_FLAGS_RELWITHDEBINFO:-O3-g-fabi-version=2-fno-omit-frame-pointer-fno-strict-aliasing-DDBUG_OFF--Configuringdone--Generatingdone--Buildfileshavebeenwrittento:/soft/mysql-5.7.26

9.编译源码,这时使用-j 6选项来使用6个进程同时进行编译

-bash-4.2$make-j6.........BuildingCXXobjectsql/CMakeFiles/sql.dir/event_data_objects.cc.oBuildingCXXobjectsql/CMakeFiles/sql.dir/des_key_file.cc.oBuildingCXXobjectsql/CMakeFiles/sql.dir/event_db_repository.cc.o[97%]BuildingCXXobjectsql/CMakeFiles/sql.dir/event_parse_data.cc.o[97%]BuildingCXXobjectsql/CMakeFiles/sql.dir/event_queue.cc.o[97%]BuildingCXXobjectsql/CMakeFiles/sql.dir/event_scheduler.cc.o[97%]BuildingCXXobjectsql/CMakeFiles/sql.dir/events.cc.o[97%]BuildingCXXobjectsql/CMakeFiles/sql.dir/mf_iocache.cc.o[97%]BuildingCXXobjectsql/CMakeFiles/sql.dir/mysqld.cc.o[97%]BuildingCXXobjectsql/CMakeFiles/sql.dir/mysqld_thd_manager.cc.o[97%]BuildingCXXobjectsql/CMakeFiles/sql.dir/protocol_callback.cc.o[97%]BuildingCXXobjectsql/CMakeFiles/sql.dir/signal_handler.cc.o[98%]BuildingCXXobjectsql/CMakeFiles/sql.dir/sql_audit.cc.o[98%]BuildingCXXobjectsql/CMakeFiles/sql.dir/sql_client.cc.o[98%]BuildingCXXobjectsql/CMakeFiles/sql.dir/srv_session.cc.o[98%]BuildingCXXobjectsql/CMakeFiles/sql.dir/srv_session_info_service.cc.o[98%]BuildingCXXobjectsql/CMakeFiles/sql.dir/srv_session_service.cc.o[98%]BuildingCXXobjectsql/CMakeFiles/sql.dir/auth/sha2_password_common.cc.o[98%]BuildingCXXobjectsql/CMakeFiles/sql.dir/mysqld_daemon.cc.oLinkingCXXstaticlibrary../archive_output_directory/libsql.a[98%]BuilttargetsqlScanningdependenciesoftargetmysqldScanningdependenciesoftargetpfs_connect_attr-t[99%]BuildingCXXobjectsql/CMakeFiles/mysqld.dir/main.cc.oLinkingCXXexecutablemysqld[100%][100%][100%]BuildingCXXobjectstorage/perfschema/unittest/CMakeFiles/pfs_connect_attr-t.dir/__/__/__/sql/sql_builtin.cc.oBuildingCXXobjectstorage/perfschema/unittest/CMakeFiles/pfs_connect_attr-t.dir/pfs_connect_attr-t.cc.oBuildingCobjectstorage/perfschema/unittest/CMakeFiles/pfs_connect_attr-t.dir/__/__/__/mysys/string.c.oLinkingCXXexecutablepfs_connect_attr-t[100%]Builttargetmysqld[100%]Builttargetpfs_connect_attr-t

10.安装

-bash-4.2$makeinstall.................--Installing:/mysqlsoft/mysql/mysql-test/./t/wl6661.test--Installing:/mysqlsoft/mysql/mysql-test/./t/wl6711_heap_to_disk.test--Installing:/mysqlsoft/mysql/mysql-test/./t/wl6978.test--Installing:/mysqlsoft/mysql/mysql-test/./t/xa.test--Installing:/mysqlsoft/mysql/mysql-test/./t/xa_debug.test--Installing:/mysqlsoft/mysql/mysql-test/./t/xa_gtid-master.opt--Installing:/mysqlsoft/mysql/mysql-test/./t/xa_gtid.test--Installing:/mysqlsoft/mysql/mysql-test/./t/xa_prepared_binlog_off-master.opt--Installing:/mysqlsoft/mysql/mysql-test/./t/xa_prepared_binlog_off.test--Installing:/mysqlsoft/mysql/mysql-test/./t/xml.test--Installing:/mysqlsoft/mysql/mysql-test/./valgrind.supp--Installing:/mysqlsoft/mysql/mysql-test/./mtr--Installing:/mysqlsoft/mysql/mysql-test/./mysql-test-run--Installing:/mysqlsoft/mysql/mysql-test/./Makefile--Installing:/mysqlsoft/mysql/mysql-test/./cmake_install.cmake--Installing:/mysqlsoft/mysql/mysql-test/./CTestTestfile.cmake--Installing:/mysqlsoft/mysql/./COPYING-test--Installing:/mysqlsoft/mysql/./README-test--Up-to-date:/mysqlsoft/mysql/mysql-test/mtr--Up-to-date:/mysqlsoft/mysql/mysql-test/mysql-test-run--Installing:/mysqlsoft/mysql/mysql-test/lib/My/SafeProcess/my_safe_process--Up-to-date:/mysqlsoft/mysql/mysql-test/lib/My/SafeProcess/my_safe_process--Installing:/mysqlsoft/mysql/mysql-test/lib/My/SafeProcess/Base.pm--Installing:/mysqlsoft/mysql/support-files/mysqld_multi.server--Installing:/mysqlsoft/mysql/support-files/mysql-log-rotate--Installing:/mysqlsoft/mysql/support-files/magic--Installing:/mysqlsoft/mysql/share/aclocal/mysql.m4--Installing:/mysqlsoft/mysql/support-files/mysql.server[root@localhostmysqlsoft]#chmod-R775mysql

11.配置mysql参数,只是设置几个简单的mysql运行参数

[root@localhostmysql]#vi/mysqlsoft/mysql/my.cnf[mysqld]basedir=/mysqlsoft/mysqldatadir=/mysqldata/mysqlbind-address=0.0.0.0user=mysqlport=3306log-error=/mysqldata/mysql/mysql.errpid-file=/mysqldata/mysql/mysqld.pidsocket=/mysqlsoft/mysql/mysql.sockcharacter-set-server=utf8mb4default-storage-engine=INNODBexplicit_defaults_for_timestamp=true[root@localhostmysql]#cdbin[root@localhostbin]#./mysqld--defaults-file=/mysqlsoft/mysql/my.cnf--initialize--basedir=/mysqlsoft/mysql--datadir=/mysqldata/mysql--user=mysql

查看日志信息

[root@localhostmysql]#tail-fmysql.err2019-06-17T06:28:34.137849Z0[Warning]InnoDB:Newlogfilescreated,LSN=457902019-06-17T06:28:35.342112Z0[Warning]InnoDB:Creatingforeignkeyconstraintsystemtables.2019-06-17T06:28:35.465187Z0[Warning]NoexistingUUIDhasbeenfound,soweassumethatthisisthefirsttimethatthisserverhasbeenstarted.GeneratinganewUUID:2296e390-90c9-11e9-9a9f-005056a390e6.2019-06-17T06:28:35.471829Z0[Warning]Gtidtableisnotreadytobeused.Table'mysql.gtid_executed'cannotbeopened.2019-06-17T06:28:35.474533Z1[Note]Atemporarypasswordisgeneratedforroot@localhost:Ldp#HUPR(7hH

其中[Note] A temporary password is generated for root@localhost:后面跟的是mysql数据库登录的临时密码,各人安装生成的临时密码不一样。可以看到到日志文件没有报错,而且有了临时密码,表示初始化成功。

12.如果想服务能够部署自动支持安全连接,使用mysql_ssl_rsa_setup工具来创建缺省SSL与RSA文件

[root@localhostbin]#./mysql_ssl_rsa_setup--datadir=/mysqldata/mysqlGeneratinga2048bitRSAprivatekey...........................+++.......+++writingnewprivatekeyto'ca-key.pem'-----Generatinga2048bitRSAprivatekey.......................................................................................................+++...................................................................................................................................................+++writingnewprivatekeyto'server-key.pem'-----Generatinga2048bitRSAprivatekey.....................................+++...........+++writingnewprivatekeyto'client-key.pem'-----

13.启动MySQL

[root@localhostbin]#./mysqld_safe--user=mysql&[1]19442[root@localhostbin]#2019-06-17T06:34:01.654203Zmysqld_safeLoggingto'/mysqldata/mysql/mysql.err'.2019-06-17T06:34:01.750954Zmysqld_safeStartingmysqlddaemonwithdatabasesfrom/mysqldata/mysql

14.配置自动启动MySQL

[root@localhost~]#cp/mysqlsoft/mysql/support-files/mysql.server/etc/init.d/mysqld[root@localhost~]#chmod755/etc/init.d/mysqld[root@localhost~]#systemctlenablemysqldmysqld.serviceisnotanativeservice,redirectingto/sbin/chkconfig.Executing/sbin/chkconfigmysqldon

14.配置环境变量

[root@localhost~]#vi/etc/profile#/etc/profile#Systemwideenvironmentandstartupprograms,forloginsetup#Functionsandaliasesgoin/etc/bashrc#It'sNOTagoodideatochangethisfileunlessyouknowwhatyou#aredoing.It'smuchbettertocreateacustom.shshellscriptin#/etc/profile.d/tomakecustomchangestoyourenvironment,asthis#willpreventtheneedformerginginfutureupdates.exportMYSQL_HOME=/mysqlsoft/mysql/exportPATH=$PATH:$MYSQL_HOME/bin

15.登录MySQL并修改root用户密码

-bash-4.2$mysql-uroot-pEnterpassword:WelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis2Serverversion:5.7.26Copyright(c)2000,2019,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.mysql>ALTERUSER'root'@'localhost'IDENTIFIEDBY'123456';QueryOK,0rowsaffected(0.00sec)

到此使用源码来安装MySQL就完成了。

感谢各位的阅读,以上就是“Linux怎么用源码安装MySQL 5.7”的内容了,经过本文的学习后,相信大家对Linux怎么用源码安装MySQL 5.7这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!