天天看點

centos 6.5_64bit最小化安裝環境下源碼安裝mysql-5.6

一、操作環境

華為雲服務 Centos 6.5_64bit最小化安裝内網IP:10.124.156.237

mysql-5.6.20.tar.gz

二、源碼編譯安裝流程

1.基礎環境搭建

由于作業系統是最小化安裝,是以一些常用的編譯環境是沒有安裝的;加上我們的操作環境是内網,是以不能使用yum源。解決這個問題,可以從華為雲購買一個臨時公網Ip與我們伺服器的内網IP進行邦定,這樣我們就可以使用yum源來安裝必要的編譯環境了。

yum -y install gccgcc-c++ vim tree make cmake autoconf openssl openssl-devel openssl-clients curlcurl-devel wget rsync expect readline readline-devel bison bison-devel  pcre pcre-devel zlib-devel zlib  freetype freetype-devel

上面這段代碼可以滿足基本的環境操作,不僅僅适用于在安裝mysql的過程中。

2.mysql使用者以及必需目錄

在mysql運作中涉及到很多權限的問題,是以提前進行這方面的準備,避免在後期遇到一些不必要的權限問題。

groupadd mysql

useradd -g mysql mysql

mkdir -p/home/mysql/data/data_3306/binlog /home/mysql/data/data_3306/relay_log/home/mysql/data/data_3306/socket

mkdir -p/home/mysql/data/data_3307/binlog /home/mysql/data/data_3307/relay_log/home/mysql/data/data_3307/socket

chown –Rmysql.mysql  /home/mysql/

cd /usr/local/src/

tar xf mysql-5.6.20.tar.gz

cd mysql-5.6.20

cmake .-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/mysql/data-DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1-DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock-DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1-DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci

make && makeinstall

/usr/local/mysql/scripts/mysql_install_db--basedir=/usr/local/mysql --datadir=/home/mysql/data --user=mysql

首先修改配置檔案

vim /etc/my.cnf

[mysqld_multi]

mysqld =/usr/local/mysql/bin/mysqld_safe

mysqladmin =/usr/local/mysql/bin/mysqladmin

#log = /home/mysql/data/log/mysqld_multi.log

#user = root

#password = password

[mysqld1]

socket =/home/mysql/data/data_3306/socket/mysql.sock

port = 3306

pid-file =/home/mysql/data/data_3306/3306.pid

datadir =/home/mysql/data/data_3306

user = mysql

skip-name-resolve

lower_case_table_names=1

innodb_file_per_table=1

back_log = 50

max_connections = 300

max_connect_errors =1000

table_open_cache =2048

max_allowed_packet =16M

binlog_cache_size = 2M

max_heap_table_size =64M

sort_buffer_size = 2M

join_buffer_size = 2M

thread_cache_size = 64

thread_concurrency = 8

query_cache_size = 64M

query_cache_limit = 2M

ft_min_word_len = 4

default-storage-engine= MYISAM

thread_stack = 192K

transaction_isolation= REPEATABLE-READ

tmp_table_size = 64M

log-bin=mysql-bin

binlog_format=mixed

slow_query_log

long_query_time = 1

server-id = 1

key_buffer_size = 8M

read_buffer_size = 2M

read_rnd_buffer_size =2M

bulk_insert_buffer_size= 64M

myisam_sort_buffer_size= 128M

myisam_max_sort_file_size= 10G

myisam_repair_threads= 1

myisam_recover

innodb_additional_mem_pool_size= 16M

innodb_buffer_pool_size= 200M

innodb_data_file_path= ibdata1:10M:autoextend

innodb_file_io_threads= 8

innodb_thread_concurrency= 16

innodb_flush_log_at_trx_commit= 1

innodb_log_buffer_size= 16M

innodb_log_file_size =512M

innodb_log_files_in_group= 3

innodb_max_dirty_pages_pct= 60

innodb_lock_wait_timeout= 120

[mysqld2]

socket =/home/mysql/data/data_3307/socket/mysql.sock

port = 3307

pid-file =/home/mysql/data/data_3307/3307.pid

datadir = /home/mysql/data/data_3307

[mysqldump]

quick

max_allowed_packet =256M

[mysql]

no-auto-rehash

[myisamchk]

key_buffer_size = 512M

sort_buffer_size =512M

read_buffer = 8M

write_buffer = 8M

[mysqlhotcopy]

interactive-timeout

[mysqld_safe]

open-files-limit =8192

其次進行初始化操作:

scripts/mysql_install_db--basedir=/usr/local/mysql --datadir=/home/mysql/data/data_3306 --user=mysql

scripts/mysql_install_db--basedir=/usr/local/mysql --datadir=/home/mysql/data/data_3307 --user=mysql

這一步至關重要,因為涉及到啟動時會報找不到my_print_defaults指令的錯誤,同時也為了以後友善操作。

vim /etc/profile

在末行添加exportPATH=$PATH:/usr/sbin/:/usr/local/mysql/bin

儲存退出執行:source /etc/profile

/usr/local/mysql/bin/mysqld_multi start 1,2  –>  mysqld_multi start 1,2

mysqld_multi stop 1

mysqld_multi stop 2

mysql -S/home/mysql/data/data_3306/socket/mysql.sock #第一個執行個體連接配接

mysql -S /home/mysql/data/data_3307/socket/mysql.sock  #第二個執行個體連接配接

mysql –h 10.124.156.237 –P 3306 –u root –p123  #指定端口号連接配接

mysql –h 10.124.156.237 –P 3307 –u root –p123

三、單機多執行個體作為多機‘從’設定

四、報錯總結

1.啟動報錯

WARNING: my_print_defaults command not found.

Please make sure you have this command available and

in your path. The command is available from the latest

MySQL distribution.

ABORT: Can't find command 'my_print_defaults'.

This command is available from the latest MySQL

distribution. Please make sure you have the command

in your PATH.

問題解析:找不到my_print_defaults指令,沒有設定環境變量的緣故

問題解決:cp /usr/local/mysql/bin/my_print_defaults/usr/bin/

          cp/usr/local/mysql/bin/mysqld_multi /usr/bin/

2.     初始化報錯

 FATAL ERROR: The parentdirectory for the data directory '/home/data/data_3306' does not exis

If that path was really intended, please create that directory path andthen

restart this script.

If some other path was intended, please use the correct path whenrestarting this script.

問題解析:檔案目錄不存在。沒有執行編譯安裝中的第2步,或者配置檔案my.cnf中填寫有誤

問題解決:環境變量的配置

       vim /etc/profile

檢查配置檔案my.cnf

本文轉自 南非波波 51CTO部落格,原文連結:http://blog.51cto.com/nanfeibobo/1598206,如需轉載請自行聯系原作者

繼續閱讀