MySQL5.7.20編譯安裝


1:官網下載source code源碼安裝文件
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.20.tar.gz

  

2:安裝准備

先看一下文件和路徑:

[root@16-31 mysql]# pwd
/home/mysql
[root@16-31 mysql]# ls
mysql-boost-5.7.20.tar.gz

  

我們看一下官網給出的源碼安裝需要的條件:

CMake, which is used as the build framework on all platforms. CMake can be downloaded from http://www.cmake.org.

A good make program. Although some platforms come with their own make implementations, it is highly recommended that you use GNU make 3.75 or higher. It may already be available on your system as gmake. GNU make is available from http://www.gnu.org/software/make/.

A working ANSI C++ compiler. See the description of the FORCE_UNSUPPORTED_COMPILER. option for some guidelines.

The Boost C++ libraries are required to build MySQL (but not to use it). Boost 1.59.0 must be installed. To obtain Boost and its installation instructions, visit the official site. After Boost is installed, tell the build system where the Boost files are located by defining the WITH_BOOST option when you invoke CMake. For example:

shell> cmake . -DWITH_BOOST=/usr/local/boost_1_59_0
Adjust the path as necessary to match your installation.

The ncurses library.

Sufficient free memory. If you encounter problems such as “internal compiler error” when compiling large source files, it may be that you have too little memory. If compiling on a virtual machine, try increasing the memory allocation.

Perl is needed if you intend to run test scripts. Most Unix-like systems include Perl. On Windows, you can use a version such as ActiveState Perl.

  

上面是官網給的例子,我們先需要下載一個Boost C++ 1.59.0(這是一組擴充C++功能的經過同行評審(Peer-reviewed)且開放源代碼程序庫。大多數的函數為了能夠以開放源代碼、封閉項目的方式運作,而授權於Boost軟件許可協議(Boost Software License)之下。),下載地址:

https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz/download

  

接下來我們開始進行一些准備工作(安裝依賴包,用戶以及目錄):

yum -y install gcc gcc-c++ ncurses ncurses-devel bison libgcrypt perl make cmake
groupadd mysql
useradd -r -g mysql -s /bin/false -M mysql
mkdir -p /home/mysql/{data,log,tmp}
ls /home/mysql/
chown -R mysql:mysql /home/mysql/

  

3:安裝

解壓兩個壓縮文件,MySQL和Boost,然后開始進行編譯安裝:

[root@16-31 mysql-5.7.20]# cmake . -DCMAKE_INSTALL_PREFIX=/home/mysql -DMYSQL_DATADIR=/home/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost

  

然后進行make

make

  

這個過程時間會比較久,我這邊大概兩個小時的樣子,然后安裝:

make install

  

然后我們先把安裝目錄添加到環境變量中:

[root@mdw mysql]# echo "export PATH=$PATH:/home/mysql/bin">>/etc/profile
[root@mdw mysql]# source /etc/profile

  

以上步驟完成以后就是初始化數據庫了:

[root@mdw datafile]# mysqld --defaults-file=/etc/my.cnf  --initialize --user='mysql' --log_error_verbosity --explicit_defaults_for_timestamp

  

OK,現在我們初始化也完成了,接下來我們配置一下我們的my.cnf文件

[client]
port            = 3306
socket          = /home/datafile/mysql3306/temp/mysql.sock
[mysqld]
# Skip #
skip_name_resolve              = 1  
skip-external-locking          = 1 
symbolic-links= 0                    


# GENERAL #
user = mysql
default_storage_engine = InnoDB
character-set-server = utf8
socket  = /home/datafile/mysql3306/temp/mysql.sock
pid_file =/home/datafile/mysql3306/temp/mysqld.pid
basedir = /home/mysql
port = 3306
bind-address = 0.0.0.0 
log-warnings = 2  
explicit_defaults_for_timestamp = off 
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#read_only=on
sql_mode=NO_ENGINE_SUBSTITUTION  
# MyISAM #
key_buffer_size                = 32M    #size of the buffer used for index blocks#
#myisam_recover                 = FORCE,BACKUP

# SAFETY #
max_allowed_packet             = 16M 
max_connect_errors             = 1000000 
sysdate_is_now                 = 1
#innodb	= FORCE
#innodb_strict_mode = 1

# Replice #
 server-id = 313306 
 relay_log = mysqld-relay-bin
 gtid_mode = on
 enforce-gtid-consistency
 log-slave-updates = on 
 master_info_repository =TABLE 
 relay_log_info_repository =TABLE 
# rpl_semi_sync_master_enabled=1
# rpl_semi_sync_master_timeout=200     # 0.2 second

# DATA STORAGE #
 datadir = /home/datafile/mysql3306/data/
 tmpdir	= /home/datafile/mysql3306/temp/
 
# BINARY LOGGING #
 log_bin =/home/datafile/mysql3306/log/mysql-bin
 max_binlog_size = 1000M
 binlog_format = row
 expire_logs_days = 7
# sync_binlog = 1

 # CACHES AND LIMITS #
 tmp_table_size                 = 32M
 max_heap_table_size            = 32M
 query_cache_type               = 0
 query_cache_size               = 0
 max_connections                = 4000
 thread_cache_size              = 2048
 open_files_limit               = 65535
 table_definition_cache         = 4096
 table_open_cache               = 4096
 sort_buffer_size               = 20M
 read_buffer_size               = 2M
 read_rnd_buffer_size           = 2M
 #thread_concurrency             = 24
 join_buffer_size = 1M
# table_cache = 32768
 thread_stack = 512k
 max_length_for_sort_data = 16k


 # INNODB #
 innodb_flush_method            = O_DIRECT 
 innodb_log_buffer_size = 16M
 innodb_flush_log_at_trx_commit = 2 
 innodb_file_per_table          = 1 
 innodb_buffer_pool_size        = 2G
 innodb_buffer_pool_instances = 8
 innodb_stats_on_metadata = off 
 innodb_open_files = 8192
 innodb_read_io_threads = 8 
 innodb_write_io_threads = 16
 innodb_io_capacity = 20000
 innodb_thread_concurrency = 0 
 innodb_lock_wait_timeout = 60
 innodb_old_blocks_time=1000
 innodb_use_native_aio = 1
 innodb_purge_threads=1  
 innodb_change_buffering=all
 innodb_log_file_size = 128M 
 innodb_log_files_in_group = 3
 innodb_data_file_path  = ibdata1:1024M:autoextend
 
 # LOGGING #
 log_error                      = /home/datafile/mysql3306/log/mysql-error.log
 # log_queries_not_using_indexes  = 1
 # slow_query_log                 = 1
 slow_query_log_file            = /home/datafile/mysql3306/log/slowlog_36215.log

 # TimeOut #
 interactive_timeout = 30 
 wait_timeout        = 30


[mysqldump]
quick   
max_allowed_packet = 16M

[mysql]
no-auto-rehash  


[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

  

這里要說明下,就是參數要根據自己的機器配置,不能直接照抄使用,然后直接啟動mysql:

mysqld_safe --defaults-file=/etc/my.cnf &

  

我們從日志中找到初始密碼:

2017-12-11T06:59:05.094646Z 1 [Note] A temporary password is generated for root@localhost: ,fsQ:tkik6un

 

登錄修改密碼就好了。 最后,我們將我們的編譯包打包,以后可以直接拷貝使用。

4:解壓使用編譯壓縮包

先拷貝:

scp   /home/mysql.tar  sa@172.16.16.34:/home/sa/

 

解壓:

[root@sdw1 home]# mv mysql.tar /home/
[root@sdw1 home]# tar zxvf mysql.tar

 

然后我們創建MySQL相關的用戶和目錄以及授權等:

groupadd mysql
useradd -r -g mysql -s /bin/false -M mysql
mkdir -p /home/datafile/mysql3306/{data,log,temp}
ls /home/datafile/mysql3306
chown -R mysql:mysql /home/datafile/mysql3306
echo "export PATH=$PATH:/home/mysql/bin">>/etc/profile
source /etc/profile

  

然后使用剛才配置文件再初始化一下(要修改個別參數):

[root@sdw1 mysql3306]# mysqld --defaults-file=/etc/my.cnf  --initialize --user='mysql' --log_error_verbosity --explicit_defaults_for_timestamp
[root@sdw1 mysql3306]# mysqld_safe --defaults-file=/etc/my.cnf &

 

然后找到密碼初始化搞定。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM