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

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/

3.     源碼編譯安裝

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

4.     初始化設置

1)單實例初始化

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

2)多實例初始化

首先修改配置文件

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

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

[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

5.     修改環境變數

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

vim /etc/profile

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

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

6.     Mysql資料庫的啟動和關閉

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

mysqld_multi stop 1

mysqld_multi stop 2

7.     資料庫的連接

1)本地連接:

mysql -S/home/mysql/data/data_3306/socket/mysql.sock #第一個實例連接

mysql -S /home/mysql/data/data_3307/socket/mysql.sock  #第二個實例連接

2)遠程連接:

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

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

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

檢查配置文件my.cnf

以下文章點擊率最高

Loading…

     

如果這文章對你有幫助,請掃左上角微信支付-支付寶,給於打賞,以助博客運營