標籤:mysql安裝
一、作業環境
華為雲端服務 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
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
本文出自 “守望海豚” 部落格,謝絕轉載!
centos 6.5_64bit迷你安裝環境下源碼安裝mysql-5.6