mysql原始碼安裝

e71hao發表於2016-08-26
1.原始碼包安裝,進入mysql.com網站,註冊一個oracle賬號,選擇5.6community Editon ,選擇source code ,下載類似:
mysql-xxx(version).tar.gz安裝包,大約30M。
2.上傳到Linux上,解壓命令 tar -xvzf mysql-5.6.32.tar.gz
3.進入到解壓後資料夾mysql-5.6.32,執行命令如下
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_PARTITION_STORAGE_ENGINE=1 

第一次執行很有可能會報錯。在最後,cmake會提示你少了哪些安裝必須的包,比如我的系統提示我缺少了 ncurses-devel,執行
如下命令安裝 yum install ncurses-devel。刪除CMakeCache.txt檔案,重新執行cmake.

4.cmake 進行安裝前的驗證檢查,檢查最後透過會輸出如下資訊:
BLE_DOWNLOADS=1 to automatically download and build required components from source.
-- If you are inside a firewall, you may need to use an http proxy: export http_proxy=
Warning: Bison executable not found in PATH
-- Library mysqlserver depends on OSLIBS -lpthread;m;rt;crypt;dl
-- CMAKE_BUILD_TYPE: RelWithDebInfo
-- COMPILE_DEFINITIONS: HAVE_CONFIG_H
-- 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_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
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mysql/mysql-5.6.32

5.安裝前cmake 成功執行後,執行make 命令,執行編譯,大概需要10分鐘。最後輸出如下資訊,表示built完成
[100%] Built target mysql_embedded
Scanning dependencies of target mysqltest_embedded
[100%] Building CXX object libmysqld/examples/CMakeFiles/mysqltest_embedded.dir/__/__/client/mysqltest.cc.o
Linking CXX executable mysqltest_embedded
[100%] Built target mysqltest_embedded
Scanning dependencies of target my_safe_process
[100%] Building CXX object mysql-test/lib/My/SafeProcess/CMakeFiles/my_safe_process.dir/safe_process.cc.o
Linking CXX executable my_safe_process
[100%] Built target my_safe_process

6.接著執行命令:make install 
-- Installing: /usr/local/mysql/sql-bench/innotest1a
-- Installing: /usr/local/mysql/sql-bench/innotest2
-- Installing: /usr/local/mysql/sql-bench/test-create
-- Installing: /usr/local/mysql/sql-bench/crash-me
-- Installing: /usr/local/mysql/sql-bench/innotest1
-- Installing: /usr/local/mysql/sql-bench/bench-init.pl
-- Installing: /usr/local/mysql/sql-bench/test-wisconsin
-- Installing: /usr/local/mysql/sql-bench/compare-results
-- Installing: /usr/local/mysql/sql-bench/copy-db
7.進入到指定的安裝目錄下/usr/local/mysql
[root@mysqlIns mysql-5.6.32]# cd /usr/local/mysql
[root@mysqlIns mysql]# ls
bin      data  include  man         README   share      support-files
COPYING  docs  lib      mysql-test  scripts  sql-bench
8.進入data,你會發現只有test庫,沒有mysql庫,performance_schema庫。安裝mysql庫,初始化Innodb,執行命令:
 ./scripts/mysql_install_db  --user=mysql

有錯誤報錯如下:
2016-08-26 11:42:00 22040 [ERROR] InnoDB: space header page consists of zero bytes in data file ./ibdata1
2016-08-26 11:42:00 22040 [ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!
2016-08-26 11:42:00 22040 [ERROR] Plugin 'InnoDB' init function returned error.
2016-08-26 11:42:00 22040 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-08-26 11:42:00 22040 [ERROR] Unknown/unsupported storage engine: InnoDB
2016-08-26 11:42:00 22040 [ERROR] Aborting

解決辦法:把innodb在datadir目錄下的innodb系統檔案ibdata1,重做日誌檔案ib_logfile0-4,二進位制日誌binlog*刪除掉。
重新執行 ./scripts/mysql_install_db  --user=mysql 問題解決。
9.最後啟動mysql,大功告成,啟動mysql
mysqld_safe --defaults-file=/usr/local/mysql/my.cnf 

10.更改root密碼,按照提示
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
  ./bin/mysqladmin -u root password 'new-password'
  ./bin/mysqladmin -u root -h mysqlIns password 'new-password'

11.最後貼出我的my.cnf 檔案:
[mysqld]
innodb_data_file_path=ibdata1:12M:autoextend
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-bin=/usr/local/mysql/data/binlog
server_id=3
innodb_log_buffer_size=8388608  
innodb_log_compressed_pages=ON       
innodb_log_file_size=50331648 
innodb_log_files_in_group=5        
innodb_log_group_home_dir=./
innodb_data_file_path=ibdata1:12M:autoextend

slow_query_log=on
long_query_time=5
slow_query_log_file=/usr/local/mysql/data/mysqlIns-slow.log

sql_mode=oracle

character_set_server=utf8
collation_server=utf8_general_ci

[mysqld_safe]
log-error=/usr/local/mysql/data/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid






來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30393770/viewspace-2124065/,如需轉載,請註明出處,否則將追究法律責任。

相關文章