SUSE Linux下源码编译方式安装MySQL 5.6过程分享
MySQL为开源数据库,因此可以基于源码实现安装。基于源码安装有更多的灵活性。也就是说我们可以针对自己的硬件平台选用合适的编译器来优化编译后的二进制代码,根据不同的软件平台环境调整相关的编译参数,选择自身需要选择不同的安装组件,设定需要的字符集等等一些可以根据特定应用场景所作的各种调整。本文描述了如何在源码方式下安装MySQL。
1、安装环境及介质
#安装环境 SZDB:~#cat/etc/issue WelcometoSUSELinuxEnterpriseServer10SP3(x86_64)-Kernel\r(\l). SZDB:~#uname-a LinuxSZDB2.6.16.60-0.54.5-smp#1SMPFriSep401:28:03UTC2009x86_64x86_64x86_64GNU/Linux #安装介质,可以到以下网址下载安装介质,注意下载时选择sourcecode,当前版本为5.6.17 #根据你自身的环境下载相应的安装介质,本文演示的安装介质为GenericLinux(ArchitectureIndependent),mysql-5.6.17.tar.gz http://dev.mysql.com/downloads/mysql/ #源码安装方式官方网站链接:http://dev.mysql.com/doc/refman/5.6/en/installing-source-distribution.html
2、系统需求
SourceInstallationSystemRequirements InstallationofMySQLfromsourcerequiresseveraldevelopmenttools.Someofthesetoolsareneedednomatterwhetheryouuseastandardsourcedistributionoradevelopmentsourcetree.Othertoolrequirementsdependonwhichinstallationmethodyouuse. ToinstallMySQLfromsource,yoursystemmusthavethefollowingtools,regardlessofinstallationmethod: CMake,whichisusedasthebuildframeworkonallplatforms.CMakecanbedownloadedfromhttp://www.cmake.org. Agoodmakeprogram.Althoughsomeplatformscomewiththeirownmakeimplementations,itishighlyrecommendedthatyouuseGNUmake3.75ornewer.Itmayalreadybeavailableonyoursystemasgmake.GNUmakeisavailablefromhttp://www.gnu.org/software/make/. AworkingANSIC++compiler.GCC4.2.1orlater,SunStudio12orlater,VisualStudio2010orlater,andmanycurrentvendor-suppliedcompilersareknowntowork. Perlisneededifyouintendtoruntestscripts.MostUnix-likesystemsincludePerl.OnWindows,youcanuseaversionsuchasActiveStatePerl. #使用源码安装上面的一些开发工具是需要的,比较重要的一个是Cmake工具,通常情况下os并没有安装,需要手动安装。 #如果没有cmake会收到这个错误提示:(-bash:cmake:commandnotfound)
3、安装cmake
#可以到这里下载cmake,我这里下载的是2.6.4版本 http://www.cmake.org/cmake/resources/software.html SZDB:~#cd/usr/local/src/mysql_src SZDB:/usr/local/src/mysql_src#tar-xvfcmake-2.6.4.tar.gz SZDB:/usr/local/src/mysql_src#cdcmake-2.6.4 SZDB:/usr/local/src/mysql_src/cmake-2.6.4#./bootstrap SZDB:/usr/local/src/mysql_src/cmake-2.6.4#./make SZDB:/usr/local/src/mysql_src/cmake-2.6.4#./makeinstall
4、安装MySQL
SZDB:~#groupaddmysql
SZDB:~#useradd-r-gmysqlmysql
SZDB:~#cd/usr/local/src/mysql_src
SZDB:/usr/local/src/mysql_src#tar-xvfmysql-5.6.17.tar.gz
SZDB:/usr/local/src/mysql_src#ls
mysql-5.6.17 mysql-5.6.17.tar.gz
SZDB:/usr/local/src/mysql_src#cdmysql-5.6.17/
SZDB:/usr/local/src/mysql_src/mysql-5.6.17#cmake.
..........
--Checksizeofwint_t-done
--CouldNOTfindCurses (missing: CURSES_LIBRARYCURSES_INCLUDE_PATH)
CMakeErroratcmake/readline.cmake:85(MESSAGE): Author:Leshami
Curseslibrarynotfound. Pleaseinstallappropriatepackage, Blog :http://blog.csdn.net/leshami
removeCMakeCache.txtandreruncmake.OnDebian/Ubuntu,packagenameislibncurses5-dev,
onRedhatandderivatesitisncurses-devel.
CallStack(mostrecentcallfirst):
cmake/readline.cmake:128(FIND_CURSES)
cmake/readline.cmake:202(MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:411(MYSQL_CHECK_EDITLINE)
#如果cmake期间碰到上述错误,应该安装ncurses-develrpm包,然后移除CMakeCache.txt
--Configuringincomplete,errorsoccurred!
#如有没有对应的os安装光盘,可以从下面的链接下载这个rpm包,注意对应的版本号应一致
http://www.filewatcher.com/m/ncurses-devel-5.5-18.11.x86_64.rpm.735840-0.html
SZDB:/usr/local/src/mysql_src#rpm-Uvhncurses-devel-5.5-18.11.x86_64.rpm
Preparing... ###########################################[100%]
1:ncurses-devel ###########################################[100%]
SZDB:/usr/local/src/mysql_src/mysql-5.6.17#rm-rfCMakeCache.txt
SZDB:/usr/local/src/mysql_src/mysql-5.6.17#cmake. #再次执行cmake
........
--LibrarymysqlserverdependsonOSLIBS-lpthread;m;rt;crypt;dl;aio
--Configuringdone
--Generatingdone
--Buildfileshavebeenwrittento:/usr/local/src/mysql_src/mysql-5.6.17
SZDB:/usr/local/src/mysql_src/mysql-5.6.17#make
LinkingCXXexecutablemysqltest_embedded
[100%]Builttargetmysqltest_embedded
Scanningdependenciesoftargetmy_safe_process
[100%]BuildingCXXobjectmysql-test/lib/My/SafeProcess/CMakeFiles/my_safe_process.dir/safe_process.cc.o
LinkingCXXexecutablemy_safe_process
[100%]Builttargetmy_safe_process
SZDB:/usr/local/src/mysql_src/mysql-5.6.17#makeinstall
SZDB:/usr/local/src/mysql_src/mysql-5.6.17#cd/usr/local/mysql
SZDB:/usr/local/mysql#chown-Rmysql.
SZDB:/usr/local/mysql#chgrp-Rmysql.
SZDB:/usr/local/mysql#scripts/mysql_install_db--user=mysql
..........
Tostartmysqldatboottimeyouhavetocopy
support-files/mysql.servertotherightplaceforyoursystem
PLEASEREMEMBERTOSETAPASSWORDFORTHEMySQLrootUSER!
Todoso,starttheserver,thenissuethefollowingcommands:
./bin/mysqladmin-urootpassword'new-password'
./bin/mysqladmin-uroot-hSZDBpassword'new-password'
Alternativelyyoucanrun:
./bin/mysql_secure_installation
whichwillalsogiveyoutheoptionofremovingthetest
databasesandanonymoususercreatedbydefault. Thisis
stronglyrecommendedforproductionservers.
Seethemanualformoreinstructions.
YoucanstarttheMySQLdaemonwith:
cd.;./bin/mysqld_safe&
YoucantesttheMySQLdaemonwithmysql-test-run.pl
cdmysql-test;perlmysql-test-run.pl
Newdefaultconfigfilewascreatedas./my.cnfand
willbeusedbydefaultbytheserverwhenyoustartit.
Youmayeditthisfiletochangeserversettings
..........
SZDB:/usr/local/mysql#chown-Rroot.
SZDB:/usr/local/mysql#chown-Rmysqldata
SZDB:/usr/local/mysql#cpsupport-files/mysql.server/etc/init.d/mysql.server #配置自启动
SZDB:/usr/local/mysql#cpsupport-files/my-default.cnf/etc/my.cnf #添加缺省的my.cnf配置文件
SZDB:/usr/local/mysql#bin/mysqld_safe--user=mysql& #启动mysql
[1]21004
SZDB:/usr/local/mysql#14052102:54:54mysqld_safeLoggingto'/usr/local/mysql/data/SZDB.err'.
14052102:54:54mysqld_safeStartingmysqlddaemonwithdatabasesfrom/usr/local/mysql/data
#配置环境变量,通过软链或者修改环境变量实现(PATH=$PATH:/usr/local/mysql/bin/;exportPATH)
SZDB:~#ln-fs/usr/local/mysql/bin/mysql/usr/local/bin
SZDB:~#ln-fs/usr/local/mysql/bin/mysqladmin/usr/local/bin
SZDB:~#ln-fs/usr/local/mysql/bin/mysqld_safe/usr/local/bin
#登陆到mysql
SZDB:/usr/local/bin#mysql-uroot
WelcometotheMySQLmonitor. Commandsendwith;or\g.
YourMySQLconnectionidis1
Serverversion:5.6.17Sourcedistribution
Copyright(c)2000,2014,Oracleand/oritsaffiliates.Allrightsreserved.
OracleisaregisteredtrademarkofOracleCorporationand/orits
affiliates.Othernamesmaybetrademarksoftheirrespective
owners.
Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.
mysql>showdatabases;
+--------------------+
|Database |
+--------------------+
|information_schema|
|mysql |
|performance_schema|
|test |
+--------------------+
4rowsinset(0.00sec)