源碼編譯安裝MySQL資料庫5.6.12詳細過程

1 下載安裝包download tar.gz<br />wget https://download.csdn.net/detail/mchdba/7545037<br />?<br />2 安裝cmake軟件包<br />yum install cmake -y<br /><br />3 create account of mysql<br />groupadd mysql <br />useradd -g mysql mysql <br />autoreconf –force –install<br />libtoolize –automake –force<br />automake –force –add-missing<br /><br />4 complie the sources<br />數據目錄 : /home/data/mysql/data<br />mysql軟件目錄 : /usr/local/mysql<br />mkdir -p /home/data/mysql/data<br />mkdir -p /usr/local/mysql<br />tar -xvf mysql-5.6.12.tar.gz <br />cd mysql-5.6.12<br /><br />5 預編譯<br />[root@squid-2 mysql-5.6.12]# time cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/data/mysql/data -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR==/usr/local/mysql/mysql.sock -DMYSQL_USER=mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci<br />……<br />– Check size of wint_t<br />– Check size of wint_t – done<br />– Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)<br />CMake Error at cmake/readline.cmake:85 (MESSAGE):<br /> Curses library not found. Please install appropriate package,<br /><br /><br /> remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.<br />Call Stack (most recent call first):<br /> cmake/readline.cmake:128 (FIND_CURSES)<br /> cmake/readline.cmake:202 (MYSQL_USE_BUNDLED_EDITLINE)<br /> CMakeLists.txt:325 (MYSQL_CHECK_EDITLINE)<br /><br />– Configuring incomplete, errors occurred!<br />real 0m41.872s<br />user 0m23.508s<br />sys 0m16.328s<br /><br />6 yum install make<br />ok<br />[root@472322 mysql-5.6.13]# <br />[解決]<br />刪除txt<br />[root@squid-2 mysql-5.6.12]# find / -name CMakeCache.txt<br />/root/mysql/mysql-5.6.12/CMakeCache.txt<br /><br />安裝ncurses-devel<br />yum -y install ncurses-devel<br /><br />再報錯如下:<br />– Performing Test HAVE_PEERCRED<br />CMake Error at /usr/share/cmake/Modules/CMakeCXXInformation.cmake:17 (GET_FILENAME_COMPONENT):<br /> get_filename_component called with incorrect number of arguments<br />Call Stack (most recent call first):<br /> CMakeLists.txt:3 (PROJECT)<br /><br /><br />CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage<br />CMake Error: Internal CMake error, TryCompile configure of cmake failed<br />– Performing Test HAVE_PEERCRED – Failed<br />– Library mysqlclient depends on OSLIBS -lpthread;m;rt;dl<br />– Googlemock was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source.<br />– If you are inside a firewall, you may need to use an http proxy: export http_proxy=https://foo.bar.com:80<br />Warning: Bison executable not found in PATH<br />– Library mysqlserver depends on OSLIBS -lpthread;m;rt;crypt;dl<br />– Configuring incomplete, errors occurred!<br /><br />real 0m42.841s<br />user 0m24.527s<br />sys 0m16.543s<br />– Configuring incomplete, errors occurred!<br /><br />real 0m0.510s<br />user 0m0.275s<br />sys 0m0.112s<br />[root@472322 mysql-5.6.13]# <br />yum install gcc gcc-c++ -y<br /> yum install -y ncurses-devel.x86_64<br /> yum install -y cmake.x86_64<br /> yum install -y libaio.x86_64<br /> yum install -y bison.x86_64<br />yum install -y gcc-c++.x86_64<br />[解決辦法]:刪除原來的mysql-5.6.12目錄,重新解壓縮tar.gz包<br /><br />8 重新執行編譯<br />rm -rf /root/mysql-5.6.12<br />cd /root/<br />tar -xvf mysql-5.6.12.tar.gz <br />cd /root/mysql-5.6.12<br />time cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/data/mysql/data -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR==/usr/local/mysql/mysql.sock -DMYSQL_USER=mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci<br />……<br />– Looking for asprintf – found<br />– Check size of pthread_t<br />– Check size of pthread_t – done<br />– Using cmake version 2.6.4<br />– Not building NDB<br />– Performing Test HAVE_PEERCRED<br />– Performing Test HAVE_PEERCRED – Success<br />– Library mysqlclient depends on OSLIBS -lpthread;m;rt;dl<br />– Googlemock was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source.<br />– If you are inside a firewall, you may need to use an http proxy: export http_proxy=https://foo.bar.com:80<br />– Library mysqlserver depends on OSLIBS -lpthread;m;rt;crypt;dl<br />– Configuring done<br />– Generating done<br />– Build files have been written to: /root/mysql/mysql-5.6.12<br /><br />real 0m45.943s<br />user 0m26.213s<br />sys 0m17.661s<br /><br />time make <br />這一步時間比較長,需要耐心等待,看中間是否有error信息產生。<br />會看到很多Building信息<br />……<br />[ 38%] Building CXX object storage/innobase/CMakeFiles/innobase.dir/lock/lock0iter.cc.o<br />[ 38%] Building CXX object storage/innobase/CMakeFiles/innobase.dir/lock/lock0lock.cc.o<br />[ 38%] Building CXX object storage/innobase/CMakeFiles/innobase.dir/lock/lock0wait.cc.o<br />[ 38%] Building CXX object storage/innobase/CMakeFiles/innobase.dir/log/log0log.cc.o<br />[ 39%] Building CXX object storage/innobase/CMakeFiles/innobase.dir/log/log0recv.cc.o<br />[ 39%] Building CXX object storage/innobase/CMakeFiles/innobase.dir/mach/mach0data.cc.o<br />[ 39%] Building CXX object storage/innobase/CMakeFiles/innobase.dir/mem/mem0mem.cc.o<br />……<br />[100%] Building CXX object mysql-test/lib/My/SafeProcess/CMakeFiles/my_safe_process.dir/safe_process.cc.o<br />Linking CXX executable my_safe_process<br />[100%] Built target my_safe_process<br /><br />real 21m39.375s<br />user 18m9.239s<br />sys 1m34.320s<br /><br />time make install<br />這個命令比較快<br />……<br />– Installing: /usr/local/mysql/man/man8/mysqld.8<br />– Installing: /usr/local/mysql/support-files/solaris/postinstall-solaris<br /><br />real 0m8.439s<br />user 0m3.353s<br />sys 0m4.616s<br /><br />9 init db,初始化資料庫<br />ll /home/data/mysql/data<br />cd /home/data/mysql/data<br />先賦予文件夾mysql權限<br />chown -R mysql /home/data/mysql/data<br />chgrp -R mysql /home/data/mysql/data<br />chown -R mysql /usr/local/mysql/<br />chgrp -R mysql /usr/local/mysql/<br />cd /usr/local/mysql/<br />cp support-files/my-default.cnf /etc/my56.cnf<br />scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/home/data/mysql/data –defaults-file=/usr/local/mysql/my.cnf<br />[root@localhost mysql]# scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/home/data/mysql/data –defaults-file=/usr/local/mysql/my.cnf<br />Installing MySQL system tables…/usr/local/mysql/bin/mysqld: File '/home/data/mysql/binlog/mysql-bin.index' not found (Errcode: 2 – No such file or directory)<br />2014-06-27 10:47:14 9686 [ERROR] Aborting<br /><br />2014-06-27 10:47:14 9686 [Note] Binlog end<br />2014-06-27 10:47:14 9686 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete<br /><br />[root@localhost mysql]# mkdir -p /home/data/mysql/binlog/<br />[root@localhost mysql]#<br />[root@localhost mysql]# chown -R mysql /home/data/mysql/binlog/<br />[root@localhost mysql]# chgrp -R mysql /home/data/mysql/binlog/<br />建好目錄,再執行資料庫初始化:<br />[root@472322 mysql56]# scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/home/data/mysql/data –defaults-file=/usr/local/mysql/my.cnf<br />Installing MySQL system tables…2013-08-22 05:06:03 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicit_defaults_for_timestamp server option (see documentation for more details).<br />2013-08-22 05:06:03 19416 [Note] InnoDB: The InnoDB memory heap is disabled<br />2013-08-22 05:06:03 19416 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins<br />2013-08-22 05:06:03 19416 [Note] InnoDB: Compressed tables use zlib 1.2.3<br />2013-08-22 05:06:03 19416 [Note] InnoDB: Using CPU crc32 instructions<br />2013-08-22 05:06:03 19416 [Note] InnoDB: Initializing buffer pool, size = 128.0M<br />2013-08-22 05:06:03 19416 [Note] InnoDB: Completed initialization of buffer pool<br />2013-08-22 05:06:03 19416 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!<br />2013-08-22 05:06:03 19416 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB<br />2013-08-22 05:06:03 19416 [Note] InnoDB: Database physically writes the file full: wait…<br />2013-08-22 05:06:03 19416 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB<br />2013-08-22 05:06:03 19416 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB<br />2013-08-22 05:06:03 19416 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0<br />2013-08-22 05:06:03 19416 [Warning] InnoDB: New log files created, LSN=45781<br />2013-08-22 05:06:03 19416 [Note] InnoDB: Doublewrite buffer not found: creating new<br />2013-08-22 05:06:03 19416 [Note] InnoDB: Doublewrite buffer created<br />2013-08-22 05:06:03 19416 [Note] InnoDB: 128 rollback segment(s) are active.<br />2013-08-22 05:06:03 19416 [Warning] InnoDB: Creating foreign key constraint system tables.<br />2013-08-22 05:06:03 19416 [Note] InnoDB: Foreign key constraint system tables created<br />2013-08-22 05:06:03 19416 [Note] InnoDB: Creating tablespace and datafile system tables.<br />2013-08-22 05:06:03 19416 [Note] InnoDB: Tablespace and datafile system tables created.<br />2013-08-22 05:06:03 19416 [Note] InnoDB: Waiting for purge to start<br />2013-08-22 05:06:03 19416 [Note] InnoDB: 5.6.13 started; log sequence number 0<br />2013-08-22 05:06:04 19416 [Note] Binlog end<br />2013-08-22 05:06:04 19416 [Note] InnoDB: FTS optimize thread exiting.<br />2013-08-22 05:06:04 19416 [Note] InnoDB: Starting shutdown…<br />2013-08-22 05:06:05 19416 [Note] InnoDB: Shutdown completed; log sequence number 1625977<br />OK<br /><br />Filling help tables…2013-08-22 05:06:05 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicit_defaults_for_timestamp server option (see documentation for more details).<br />2013-08-22 05:06:05 19439 [Note] InnoDB: The InnoDB memory heap is disabled<br />2013-08-22 05:06:05 19439 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins<br />2013-08-22 05:06:05 19439 [Note] InnoDB: Compressed tables use zlib 1.2.3<br />2013-08-22 05:06:05 19439 [Note] InnoDB: Using CPU crc32 instructions<br />2013-08-22 05:06:05 19439 [Note] InnoDB: Initializing buffer pool, size = 128.0M<br />2013-08-22 05:06:05 19439 [Note] InnoDB: Completed initialization of buffer pool<br />2013-08-22 05:06:05 19439 [Note] InnoDB: Highest supported file format is Barracuda.<br />2013-08-22 05:06:05 19439 [Note] InnoDB: 128 rollback segment(s) are active.<br />2013-08-22 05:06:05 19439 [Note] InnoDB: Waiting for purge to start<br />2013-08-22 05:06:05 19439 [Note] InnoDB: 5.6.13 started; log sequence number 1625977<br />2013-08-22 05:06:05 19439 [Note] Binlog end<br />2013-08-22 05:06:05 19439 [Note] InnoDB: FTS optimize thread exiting.<br />2013-08-22 05:06:05 19439 [Note] InnoDB: Starting shutdown…<br />2013-08-22 05:06:06 19439 [Note] InnoDB: Shutdown completed; log sequence number 1625987<br />OK<br /><br />To start mysqld at boot time you have to copy<br />support-files/mysql.server to the right place for your system<br /><br />PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !<br />To do so, start the server, then issue the following commands:<br /><br /> /usr/local/mysql56/bin/mysqladmin -u root password 'new-password'<br /> /usr/local/mysql56/bin/mysqladmin -u root -h 472322.ea.com password 'new-password'<br /><br />Alternatively you can run:<br /><br /> /usr/local/mysql56/bin/mysql_secure_installation<br /><br />which will also give you the option of removing the test<br />databases and anonymous user created by default. This is<br />strongly recommended for production servers.<br />See the manual for more instructions.<br />You can start the MySQL daemon with:<br /> cd . ; /usr/local/mysql56/bin/mysqld_safe &<br />You can test the MySQL daemon with mysql-test-run.pl<br /> cd mysql-test ; perl mysql-test-run.pl<br />Please report any problems with the ./bin/mysqlbug script!<br />The latest information about MySQL is available on the web at<br /> https://www.mysql.com<br />Support MySQL by buying support/licenses at https://shop.mysql.com<br /><br />New default config file was created as /usr/local/mysql56/my.cnf and<br />will be used by default by the server when you start it.<br />You may edit this file to change server settings<br /><br />WARNING: Default config file /etc/my.cnf exists on the system<br />This file will be read by default by the MySQL server<br />If you do not want to use this, either remove it, or use the<br />–defaults-file argument to mysqld_safe when starting the server<br />[root@472322 mysql56]# <br /><br />10 copy start command <br />cp support-files/mysql.server /etc/init.d/mysqld5612<br />chmod 700 /etc/init.d/mysqld5612<br />echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile <br />source /etc/profile<br /><br />11 添加開機啟動<br />chkconfig –add mysqld5612<br /><br />12 start service <br />service mysqld5612 start<br />[root@squid-2 mysql]# service mysqld5612 start<br />Starting MySQL…….The server quit without updating PID f[失敗]usr/local/mysql/mysqld.pid).<br />[root@squid-2 mysql]# <br />查看日志報錯如下:<br />2014-06-24 14:56:54 31726 [Note] Server socket created on IP: '::'.<br />2014-06-24 14:56:54 31726 [ERROR] Can't start server : Bind on unix socket: Permission denied<br />2014-06-24 14:56:54 31726 [ERROR] Do you already have another mysqld server running on socket: /usr/local/mysql/mysql.sock ?<br />2014-06-24 14:56:54 31726 [ERROR] Aborting<br />解決原因是:<br />/usr/local/mysql跟目錄需要賦予mysql權限<br />根據日志文件顯示,首先檢查運行權限,再看一下/usr/local/mysql/mysql.sock,發現/usr/local/mysql目錄下並沒有該文件,是否是沒有權限寫目錄?<br />看到/usr/local/mysql目錄是root用戶,所以賦予mysql操作權限。<br />chown -R mysql.mysql /usr/local/mysql<br /> <br />[root@472322 data56]# service mysqld5612 start<br />Starting MySQL. SUCCESS! <br />[root@472322 data56]# mysql<br />Welcome to the MySQL monitor. Commands end with ; or \g.<br />Your MySQL connection id is 1<br />Server version: 5.6.13 Source distribution<br /><br />Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.<br /><br />Oracle is a registered trademark of Oracle Corporation and/or its<br />affiliates. Other names may be trademarks of their respective<br />owners.<br /><br />Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.<br /><br />mysql> show databases;<br />+——————–+<br />| Database |<br />+——————–+<br />| information_schema |<br />| mysql |<br />| performance_schema |<br />| test |<br />+——————–+<br />4 rows in set (0.00 sec)<br />mysql> <br /><br />

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *