1、環境介紹html
Centos 6.7 2.6.32-573.el6.x86_64 軟件包:percona-server-5.7.18-16.tar.gz 下載地址:https://www.percona.com/downloads/Percona-Server-LATEST/
2、編譯安裝mysql
一、安裝依賴包 #yum install cmake gcc-c++ git ncurses ncurses-devel bison bison-devel readline readline-devel -y 二、下載boost 地址: 下載的版本是boost_1_59_0.tar.gz 至於爲何是這個版本,後面會解釋! 建立目錄boost #mkdir /usr/local/boost #cp boost_1_59_0.tar.gz /usr/local/boost 注:boost是編譯安裝percona-server的必備軟件包,不然會報錯的,後面會解釋。 三、開始編譯 編譯以前建立自定義數據存放目錄: #mkdir -pv /opt/app/mysql5 而後開始解壓--編譯--安裝 #tar xf percona-server-5.7.18-16.tar.gz #cd percona-server-5.7.18-16 #cmake ./ -DCMAKE_INSTALL_PREFIX=/opt/app/mysql5 \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_BOOST=/usr/local/boost cmake過程當中可能會出現各類奇葩的報錯,根據錯誤信息解決問題,後面會解釋! 若是依賴包都安裝上以後,cmake以後,輸出的信息(部分)以下 ……………… -- Library perconaserverclient depends on OSLIBS -lpthread;/usr/lib64/libz.so;m;rt;dl -- Check size of long long -- Check size of long long - done -- Check size of long -- Check size of long - done -- Check size of int -- Check size of int - done -- Check if the system is big endian -- Searching 16 bit integer -- Using unsigned short -- Check if the system is big endian - little endian -- Googletest 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. -- If you are inside a firewall, you may need to use an https proxy: export https_proxy=http://example.com:80 -- Performing Test HAVE_UNUSED_TYPEDEFS -- Performing Test HAVE_UNUSED_TYPEDEFS - Failed -- Performing Test HAVE_MISLEADING_INDENTATION -- Performing Test HAVE_MISLEADING_INDENTATION - Failed -- Library mysqlserver depends on OSLIBS -lpthread;/usr/lib64/libz.so;m;rt;crypt;dl -- INSTALL perconaserverclient.pc lib/pkgconfig -- Skipping deb packaging on unsupported platform . -- CMAKE_BUILD_TYPE: RelWithDebInfo -- COMPILE_DEFINITIONS: _GNU_SOURCE;_FILE_OFFSET_BITS=64;HAVE_CONFIG_H;HAVE_LIBEVENT1 -- 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 -D_FORTIFY_SOURCE=2 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF -- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -O3 -D_FORTIFY_SOURCE=2 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF -- Configuring done -- Generating done -- Build files have been written to: /root/percona-server-5.7.18-16 #make #make的時間會很長,耐心等待。 ……………… Linking CXX static library libsql_embedded.a [ 99%] Built target sql_embedded [ 99%] Generating mysqlserver_depends.c Scanning dependencies of target mysqlserver [ 99%] Building C object libmysqld/CMakeFiles/mysqlserver.dir/mysqlserver_depends.c.o Linking C static library libmysqld.a /usr/bin/ar: creating /root/percona-server-5.7.18-16/libmysqld/libmysqld.a [ 99%] Built target mysqlserver Scanning dependencies of target mysql_client_test_embedded [ 99%] Building C object libmysqld/examples/CMakeFiles/mysql_client_test_embedded.dir/__/__/testclients/mysql_client_test.c.o Linking CXX executable mysql_client_test_embedded [ 99%] Built target mysql_client_test_embedded Scanning dependencies of target mysql_embedded [ 99%] Building CXX object libmysqld/examples/CMakeFiles/mysql_embedded.dir/__/__/client/completion_hash.cc.o [ 99%] Building CXX object libmysqld/examples/CMakeFiles/mysql_embedded.dir/__/__/client/mysql.cc.o [ 99%] Building CXX object libmysqld/examples/CMakeFiles/mysql_embedded.dir/__/__/client/readline.cc.o Linking CXX executable mysql_embedded [ 99%] Built target mysql_embedded Scanning dependencies of target mysqltest_embedded [ 99%] Building CXX object libmysqld/examples/CMakeFiles/mysqltest_embedded.dir/__/__/client/mysqltest.cc.o Linking CXX executable mysqltest_embedded [ 99%] 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 #make install #這一步也須要一些時間,不過比make 快 ……………… -- Installing: /opt/app/mysql5/mysql-test/./extra/binlog_tests/database.test -- Installing: /opt/app/mysql5/mysql-test/./extra/binlog_tests/binlog_mysqlbinlog_fill.inc -- Installing: /opt/app/mysql5/mysql-test/./extra/binlog_tests/binlog_row_kill_create_select.test -- Installing: /opt/app/mysql5/mysql-test/./extra/binlog_tests/enforce_gtid_consistency_trx_nontrx_consistent.test -- Installing: /opt/app/mysql5/mysql-test/./extra/binlog_tests/tmp_table.test -- Installing: /opt/app/mysql5/mysql-test/./extra/binlog_tests/binlog_mysqlbinlog_start_stop.inc -- Installing: /opt/app/mysql5/mysql-test/./Makefile -- Installing: /opt/app/mysql5/mysql-test/./asan.supp -- Installing: /opt/app/mysql5/mysql-test/./mtr -- Up-to-date: /opt/app/mysql5/mysql-test/mtr -- Up-to-date: /opt/app/mysql5/mysql-test/mysql-test-run -- Installing: /opt/app/mysql5/mysql-test/lib/My/SafeProcess/my_safe_process -- Up-to-date: /opt/app/mysql5/mysql-test/lib/My/SafeProcess/my_safe_process -- Installing: /opt/app/mysql5/mysql-test/lib/My/SafeProcess/Base.pm -- Installing: /opt/app/mysql5/support-files/mysqld_multi.server -- Installing: /opt/app/mysql5/support-files/mysql-log-rotate -- Installing: /opt/app/mysql5/support-files/magic -- Installing: /opt/app/mysql5/share/aclocal/mysql.m4 -- Installing: /opt/app/mysql5/support-files/mysql.server 到這裏percona-server就編譯安裝好了,接下來開始配置。
3、配置並啓動linux
一、建立mysql用戶以及datadir等目錄 #useradd -u2001 -d /dev/null -s /sbin/nologin -M mysql #mkdir /opt/logs/mysql5 -p && chown mysql.mysql /opt/logs/mysql5 -R #mkdir -p /opt/app/mysql5/{etc,logs,var,varinnodb,tmp} #chown mysql.mysql /opt/app/mysql5 -R 二、初始化數據庫 注意:percona-server-server 5.7已經不能使用mysql_install_db 來初始化,不然會報錯!!! #cd /opt/app/mysql5/ #./bin/mysqld --initialize --basedir=/opt/app/mysql5/ --datadir=/opt/app/mysql5/var --user=mysql 注意:若是不但願初始化後自動生成一個臨時密碼,可使用--initialize-insecure 來初始化,而後本身設置密碼 三、配置my.cnf配置文件 [client] port = 3306 socket = /opt/app/mysql5/var/mysql.sock default-character-set = utf8 [mysqld] port = 3306 socket = /opt/app/mysql5/var/mysql.sock datadir = /opt/app/mysql5/var key_buffer_size = 512M max_allowed_packet = 32M table_open_cache = 512 #sort_buffer_size = 4M sort_buffer_size = 64M net_buffer_length = 1M read_buffer_size = 16M read_rnd_buffer_size = 16M myisam_sort_buffer_size = 64M max_connections = 1024 max_connect_errors = 1024 old_passwords = 0 query_cache_type = 1 server-id = 89 skip-external-locking skip-name-resolve pid-file = /opt/app/mysql5/var/mysql.pid tmpdir = /opt/app/mysql5/tmp max_heap_table_size = 512M tmp_table_size = 512M interactive_timeout = 30 wait_timeout = 30 character-set-server = utf8 # log #general_log = 1 #general_log_file = /opt/app/mysql5/logs/query.log log-error = /opt/app/mysql5/logs/error.log expire_logs_days = 7 # slow query slow_query_log = 1 #slow_query_log_file = /opt/app/mysql5/logs/mysql-slow.log slow_query_log_file = /opt/logs/mysql5/mysql-slow.log long_query_time = 3 #################### master #################### log-bin = /opt/app/mysql5/logs/bin-log max_binlog_size = 1G binlog_format = mixed #################### end ###################### #################### slave ##################### #log-slave-updates = 1 #skip-slave-start = 1 #read-only = 1 #master-host = 192.168.1.1 #master-port = 3306 #master-user = dbslave #master-password = ruichuang@dbslave #master-connect-retry = 30 #replicate_do_db = mysql #relay-log = /opt/app/mysql5/logs/relay-log #max_relay_log_size = 1G #################### end ###################### # Uncomment the following if you are using InnoDB tables innodb_data_home_dir = /opt/app/mysql5/varinnodb innodb_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir = /opt/app/mysql5/varinnodb innodb_buffer_pool_size = 4G #innodb_additional_mem_pool_size = 512M innodb_log_file_size = 1G innodb_log_buffer_size = 256M innodb_flush_log_at_trx_commit = 2 innodb_lock_wait_timeout = 50 [mysqldump] quick max_allowed_packet = 16M [mysql] prompt = "\\u@\\h: \\d \\R:\\m:\\s>" no-auto-rehash [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout 四、啓動數據庫 #/opt/app/mysql5/support-files/mysql.server start Starting MySQL (Percona Server).2017-09-28T05:43:09.499023Z mysqld_safe error: log-error set to '/opt/app/mysql5/logs/error.log', however file don't exists. Create writable for user 'mysql'. ERROR! The server quit without updating PID file (/opt/app/mysql5/var/mysql.pid). 注意:mysql 5.7編譯安裝後,啓動MySQL 要先建立error.log文件,再啓動,不然就會報上面的錯誤。 #touch /opt/app/mysql5/logs/error.log #chown mysql.mysql /opt/app/mysql5/logs/error.log 而後從新啓動 #/opt/app/mysql5/support-files/mysql.server start Starting MySQL (Percona Server)........ SUCCESS! 注意:若是以前在服務器安裝過mysql,有/etc/my.cnf文件,必定要刪除!!! 五、鏈接mysql 在初始化數據庫過程當中,就會在/opt/app/mysql5/logs/error.log中打日誌,並生成一個臨時的密碼 #cat error.log| grep "temporary password" 2017-09-28T06:13:26.805216Z 1 [Note] A temporary password is generated for root@localhost: vit?&BHae3k? 可是使用這個密碼進入mysql以後,不能進行其餘操做,須要修改密碼,並且密碼要足夠複雜: 大小寫 字符、數字、特殊字符等 #/opt/app/mysql5/bin/mysqladmin -uroot -p password 'xxxxx' Enter password: #輸入error.log中查到的臨時密碼 mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety. 密碼修改爲功,就可使用新設置的密碼鏈接MySQL了。
4、編譯過程當中遇到的問題c++
一、第1個問題: boost的問題 解壓以後開始編譯,以下參數 #cmake ./ -DCMAKE_INSTALL_PREFIX=/opt/app/mysql5 \ > -DDEFAULT_CHARSET=utf8 \ > -DDEFAULT_COLLATION=utf8_general_ci -- Running cmake version 2.8.12.2 -- Could NOT find Git (missing: GIT_EXECUTABLE) -- Configuring with MAX_INDEXES = 64U -- The C compiler identification is GNU 4.4.7 -- The CXX compiler identification is GNU 4.4.7 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- CMAKE_GENERATOR: Unix Makefiles -- Looking for SHM_HUGETLB -- Looking for SHM_HUGETLB - found -- Looking for sys/types.h -- Looking for sys/types.h - found -- Looking for stdint.h -- Looking for stdint.h - found -- Looking for stddef.h -- Looking for stddef.h - found -- Check size of void * -- Check size of void * - done -- SIZEOF_VOIDP 8 -- Performing Test HAVE_C_SHIFT_OR_OPTIMIZATION_BUG -- Performing Test HAVE_C_SHIFT_OR_OPTIMIZATION_BUG - Failed -- Performing Test HAVE_CXX_SHIFT_OR_OPTIMIZATION_BUG -- Performing Test HAVE_CXX_SHIFT_OR_OPTIMIZATION_BUG - Failed -- Performing Test HAVE_C_FLOATING_POINT_FUSED_MADD -- Performing Test HAVE_C_FLOATING_POINT_FUSED_MADD - Failed -- Performing Test HAVE_CXX_FLOATING_POINT_FUSED_MADD -- Performing Test HAVE_CXX_FLOATING_POINT_FUSED_MADD - Failed -- Performing Test HAVE_C_FP_CONTRACT_FLAG -- Performing Test HAVE_C_FP_CONTRACT_FLAG - Failed -- Performing Test HAVE_CXX_FP_CONTRACT_FLAG -- Performing Test HAVE_CXX_FP_CONTRACT_FLAG - Failed -- MySQL 5.7.18-16 -- Packaging as: percona-server-5.7.18-16-Linux-x86_64 -- Looked for boost/version.hpp in and -- BOOST_INCLUDE_DIR BOOST_INCLUDE_DIR-NOTFOUND -- LOCAL_BOOST_DIR -- LOCAL_BOOST_ZIP -- Could not find (the correct version of) boost. -- MySQL currently requires boost_1_59_0 CMake Error at cmake/boost.cmake:81 (MESSAGE): You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory> This CMake script will look for boost in <directory>. If it is not there, it will download and unpack it (in that directory) for you. If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://example.com:80 Call Stack (most recent call first): cmake/boost.cmake:238 (COULD_NOT_FIND_BOOST) CMakeLists.txt:465 (INCLUDE) -- Configuring incomplete, errors occurred! See also "/root/percona-server-5.7.18-16/CMakeFiles/CMakeOutput.log". See also "/root/percona-server-5.7.18-16/CMakeFiles/CMakeError.log". 因而google、百度去搜索解決辦法,發現須要安裝boost,其實上面的信息已經告訴咱們了!因而下載 下載地址:http://www.boost.org/users/history/ 我開始下載使用的是1.65.0的版本,地址: https://dl.bintray.com/boostorg/release/1.65.0/source/ 而後解壓安裝: #tar xf boost_1_65_0.tar.gz #mv boost_1_65_0 /usr/local/boost #cd /usr/local/boost # ./bootstrap.sh Building Boost.Build engine with toolset gcc... tools/build/src/engine/bin.linuxx86_64/b2 Detecting Python version... 2.6 Detecting Python root... /usr Unicode/ICU support for Boost.Regex?... not found. Generating Boost.Build configuration in project-config.jam... Bootstrapping is done. To build, run: ./b2 To adjust configuration, edit 'project-config.jam'. Further information: - Command line help: ./b2 --help - Getting started guide: http://www.boost.org/more/getting_started/unix-variants.html - Boost.Build documentation: http://www.boost.org/build/doc/html/index.html 而後繼續執行: #./b2 #須要很長一些時間 ……………… common.mkdir bin.v2/libs/wave/build/gcc-4.4.7/release/threading-multi/cpplexer/re2clex gcc.compile.c++ bin.v2/libs/wave/build/gcc-4.4.7/release/threading-multi/cpplexer/re2clex/aq.o gcc.compile.c++ bin.v2/libs/wave/build/gcc-4.4.7/release/threading-multi/cpplexer/re2clex/cpp_re.o gcc.link.dll bin.v2/libs/wave/build/gcc-4.4.7/release/threading-multi/libboost_wave.so.1.65.0 common.copy stage/lib/libboost_wave.so.1.65.0 ln-UNIX stage/lib/libboost_wave.so ...failed updating 54 targets... ...skipped 6 targets... ...updated 1107 targets... 當完成到這一步就證實已經完成了boost_1_65_0的安裝,而後繼續從新編譯,添加了1個參數,以下: # cmake ./ -DCMAKE_INSTALL_PREFIX=/opt/app/mysql5 \ > -DDEFAULT_CHARSET=utf8 \ > -DDEFAULT_COLLATION=utf8_general_ci \ > -DWITH_BOOST=/usr/local/boost -- Running cmake version 2.8.12.2 -- Configuring with MAX_INDEXES = 64U -- CMAKE_GENERATOR: Unix Makefiles -- SIZEOF_VOIDP 8 -- MySQL 5.7.18-16 -- Packaging as: percona-server-5.7.18-16-Linux-x86_64 -- Local boost dir /usr/local/boost -- Found /usr/local/boost/boost/version.hpp -- BOOST_VERSION_NUMBER is #define BOOST_VERSION 106500 CMake Warning at cmake/boost.cmake:266 (MESSAGE): Boost minor version found is 65 we need 59 Call Stack (most recent call first): CMakeLists.txt:465 (INCLUDE) -- BOOST_INCLUDE_DIR /usr/local/boost -- LOCAL_BOOST_DIR /usr/local/boost -- LOCAL_BOOST_ZIP LOCAL_BOOST_ZIP-NOTFOUND -- Could not find (the correct version of) boost. -- MySQL currently requires boost_1_59_0 CMake Error at cmake/boost.cmake:81 (MESSAGE): You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory> This CMake script will look for boost in <directory>. If it is not there, it will download and unpack it (in that directory) for you. If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://example.com:80 Call Stack (most recent call first): cmake/boost.cmake:269 (COULD_NOT_FIND_BOOST) CMakeLists.txt:465 (INCLUDE) -- Configuring incomplete, errors occurred! See also "/root/percona-server-5.7.18-16/CMakeFiles/CMakeOutput.log". See also "/root/percona-server-5.7.18-16/CMakeFiles/CMakeError.log". 可是依然繼續報錯……在網上又找到了另一個解決方法因而按照此方法操做 刪除boost目錄下的全部文件: #rm -rf /usr/local/boost/* 再添加1個編譯參數,從新cmake,以下: #cmake ./ -DCMAKE_INSTALL_PREFIX=/opt/app/mysql5 \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DDOWNLOAD_BOOST=1 \ -DWITH_BOOST=/usr/local/boost 會輸出以下信息: -- Running cmake version 2.8.12.2 -- Configuring with MAX_INDEXES = 64U -- CMAKE_GENERATOR: Unix Makefiles -- SIZEOF_VOIDP 8 -- MySQL 5.7.18-16 -- Packaging as: percona-server-5.7.18-16-Linux-x86_64 -- Downloading boost_1_59_0.tar.gz to /usr/local/boost 能夠看到在本身下載boost_1_59_0.tar.gz,這就是爲何開始的時候我選在下載1_59版本的緣由!!! 可是會卡在這裏,因而中止編譯,本身在官網下載boost_1_59_0.tar.gz 放在/usr/local/boost目錄 二、cmake 過程當中的軟件包依賴問題 而後刪除percona-server-5.7.18-16目錄,從新解壓編譯 #cmake ./ -DCMAKE_INSTALL_PREFIX=/opt/app/mysql5 \ > -DDEFAULT_CHARSET=utf8 \ > -DDEFAULT_COLLATION=utf8_general_ci \ > -DWITH_BOOST=/usr/local/boost -- Running cmake version 2.8.12.2 -- Configuring with MAX_INDEXES = 64U -- CMAKE_GENERATOR: Unix Makefiles -- SIZEOF_VOIDP 8 -- MySQL 5.7.18-16 -- Packaging as: percona-server-5.7.18-16-Linux-x86_64 -- Local boost zip /usr/local/boost/boost_1_59_0.tar.gz -- cd /usr/local/boost; tar xfz /usr/local/boost/boost_1_59_0.tar.gz …… -- Check size of wint_t - done -- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at cmake/readline.cmake:66 (MESSAGE): Curses library not found. Please install appropriate package, remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel. Call Stack (most recent call first): cmake/readline.cmake:190 (FIND_CURSES) cmake/readline.cmake:264 (FIND_SYSTEM_READLINE) CMakeLists.txt:493 (MYSQL_CHECK_EDITLINE) -- Configuring incomplete, errors occurred! See also "/root/percona-server-5.7.18-16/CMakeFiles/CMakeOutput.log". See also "/root/percona-server-5.7.18-16/CMakeFiles/CMakeError.log". 結果又報了上面提示的錯誤,意思是找不到CURSES_LIBRARY, 解決方法: #rm -f CMakeCache.txt 安裝依賴包: #yum install ncurses ncurses-devel readline readline-devel -y 注意:因此上面第二步,才提到在cmake的時候會遇到各類奇葩問題,實際上是不少依賴包沒有安裝,安裝 以後,從新cmake就ok了。
mysql官方×××地址:https://downloads.mysql.com/archives/community/git
不足之處,請多多指出!
sql