一、準備依賴包mysql
yum install gcc* c++ * bison autoconfautomakezlib* libxml* ncurses-devellibmcrypt* libtool-ltdl-devel*c++
yum install cmake*web
二、添加mysql用戶和用戶組sql
groupadd mysql數據庫
useradd -s /sbin/nologin -g mysql數組
三、建立數組存放目錄緩存
Mkdir–R /work/mysqlDatabash
給mysql權限服務器
Chown–R mysql.mysql/work/mysqlDatasocket
四、編譯安裝
解壓mysql.5.5.3.7.tar.gz
Tar –xzvf mysql.5.5.3.7.tar.gz
進入mysql安裝目錄
Cd mysql.5.5.3.7
編譯配置
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/work/mysqlData
註釋
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql配置安裝目錄
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock設置sock存放目錄
-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci設置默認字符集
-DWITH_INNOBASE_STORAGE_ENGINE=1安裝innodb存儲引擎
-DWITH_READLINE=1快捷鍵功能
-DENABLED_LOCAL_INFILE=1容許從本地導入數據
-DMYSQL_DATADIR=/work/mysqlData數據存放目錄
編譯安裝
make&& make install
Copy配置文件
cp/usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
將mysql添加到系統服務中
cp/usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
設置mysql啓動級別
chkconfig --level mysqld 2345 on
5,配置mysql
修改數據文件存放位置,
Vi /etc/my.cnf
內容以下
[mysqld]
datadir=/work/mysqlData//設置數據存放目錄
socket=/tmp/mysql.sock//mysql啓動sock文件存放地址
user=mysql//mysql啓動用戶
symbolic-links=0//關閉數據分區存儲
log-bin=/work/mysqlData/logs/mysql-bin //開啓bin-log日誌,並設置目錄
expire_logs_days = 10//bin-log日誌存放時間爲10天
#log-slow-queries = /work/mysqlData/logs/slow.log //開啓慢查詢日誌(註釋)
#long_query_time = 1//慢查詢日誌最大時間
log-error=error.log//錯誤日誌名稱,
max_connections = 500//最大鏈接數
connect_timeout = 60//鏈接保存時間
key_buffer_size = 512M//MyISAM全部緩存大小
innodb_buffer_pool_size = 1024M//Innodb緩存大小(建議系統內容的3/4)
myisam_sort_buffer_size = 256M//MyISAM排序緩存區大小
read_rnd_buffer_size = 32M//MySQL的隨機讀緩衝區大小
tmp_table_size=512M//臨時表最大值
max_heap_table_size=512M//內部臨時表的最大值
back_log = 512//能暫存的鏈接數量
max_allowed_packet=32M//
server_id = 9//mysql服務id
event_scheduler = ON//設定服務器端運行執行計劃任務
[mysqld_safe]
log_warnings=2//日誌等待時間
pid-file=/var/run/mysqld/mysqld.pid//pid文件目錄
[mysql]
socket=/tmp/mysql.sock//客戶端鏈接sock文件地址
六、初始化數據,啓動服務
/usr/local/mysql/scripts/mysql_install_db --user=mysql初始化mysql數據庫。
啓動mysql
servicemysql start
關閉mysql
servicemysql stop
七、備份工具
安裝備份工具
tarzxf percona-xtrabackup-2.0.8-587.tar.gz
cd percona-xtrabackup-2.0.8
cp bin/innobackupex /usr/bin
cp bin/xtrabackup* /usr/bin
備份腳本
#!/bin/bash
LOG_FILE="/root/stat_data/logs/backup.log"
DATE_STR=`date '+%Y-%m-%d'`
echo "" >> $LOG_FILE
echo "" >> $LOG_FILE
echo "[`date '+%Y-%m-%d %T'`] Starting backup Mysql DB " >> $LOG_FILE
echo "===============================================" >> $LOG_FILE
echo "STEP 1 : call innobackupex [`date '+%Y-%m-%d %T'`]" >> $LOG_FILE
/usr/bin/innobackupex --user=root --password=snow436 --defaults-file=/etc/my.cnf /tmp/db_backup/ >> $LOG_FILE 2>&1
echo "-----------------------------------------------" >> $LOG_FILE
echo "STEP 2 : call tar zcf [`date '+%Y-%m-%d %T'`]" >> $LOG_FILE
DB_DIR_NAME=`ls -d /tmp/db_backup/$DATE_STR*`
GZFILE_NAME="/work/db_backup/db_full_$DATE_STR.tar.gz"
echo "Source path is : $DB_DIR_NAME Dest path is : $GZFILE_NAME" >> $LOG_FILE
/bin/tar zcf $GZFILE_NAME $DB_DIR_NAME >> $LOG_FILE 2>&1
#echo "-----------------------------------------------" >> $LOG_FILE
#echo "STEP 3 :scp to web1 [`date '+%Y-%m-%d %T'`]" >> $LOG_FILE
#REMOTE_DIR_NAME="zyx@web1:/work/backup/db_full"
#echo "Source is : $GZFILE_NAME Dest is : $REMOTE_DIR_NAME" >> $LOG_FILE
#/usr/bin/scp $GZFILE_NAME $REMOTE_DIR_NAME >> $LOG_FILE 2>&1
echo "-----------------------------------------------" >> $LOG_FILE
echo "STEP 4 : remove tmp file $DB_DIR_NAME and $GZFILE_NAME [`date '+%Y-%m-%d %T'`]" >> $LOG_FILE
rm -rf $DB_DIR_NAME >> $LOG_FILE 2>&1
#rm -f $GZFILE_NAME >> $LOG_FILE 2>&1
echo "----------------------------------------------">> $LOG_FILE
echo "delete old data back"
LAST_MONTH=`date +%Y-%m-%d --date="-2 week"`
DELETE_FILE="/work/db_backup/db_full_$LAST_MONTH.tar.gz"
if [ -f $DELETE_FILE ]
then `/bin/rm -rf $DELETE_FILE`
echo "deleted $DELETE_FILE" >> $LOG_FILE
fi
echo "===============================================" >> $LOG_FILE
echo "Finished !! [`date '+%Y-%m-%d %T'`]" >> $LOG_FILE
複製
複製用戶權限
grant replication slave,replication client on *.* to slave_user@'10.0.0.8' identified by 'iseeschol';
flush privileges;
主服務器增長配置。
log_bin = mysql-bin
server_id=9
從庫設置
log_bin=mysql-bin
server_id=8
relay_log = /work/mysql_data/mysql/logs/mysql-relay-bin
log_slave_updates=1
read_only=1
//設置複製格式
binlog-format=ROW
備庫中執行命令
change master to master_host='db1',
master_user='slave_user',
master_password='iseeschol',
master_log_file='mysql-bin.000020',
master_log_pos=976154084;
start slave;
一、 準備依賴包
yum install gcc* c++ * bison autoconfautomakezlib* libxml* ncurses-devellibmcrypt* libtool-ltdl-devel*
yum install cmake*
二、 添加mysql用戶和用戶組
groupaddmysql
useradd -s /sbin/nologin -g mysql
三、 建立數組存放目錄
Mkdir–R /work/mysqlData
給mysql權限
Chown–R mysql.mysql/work/mysqlData
四、 編譯安裝
解壓mysql.5.5.3.7.tar.gz
Tar –xzvf mysql.5.5.3.7.tar.gz
進入mysql安裝目錄
Cd mysql.5.5.3.7
編譯配置
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/work/mysqlData
註釋
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql配置安裝目錄
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock設置sock存放目錄
-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci設置默認字符集
-DWITH_INNOBASE_STORAGE_ENGINE=1安裝innodb存儲引擎
-DWITH_READLINE=1快捷鍵功能
-DENABLED_LOCAL_INFILE=1容許從本地導入數據
-DMYSQL_DATADIR=/work/mysqlData數據存放目錄
編譯安裝
make&& make install
Copy配置文件
cp/usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
將mysql添加到系統服務中
cp/usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
設置mysql啓動級別
chkconfig --level mysqld 2345 on
5,配置mysql
修改數據文件存放位置,
Vi /etc/my.cnf
內容以下
[mysqld]
datadir=/work/mysqlData //設置數據存放目錄
socket=/tmp/mysql.sock //mysql啓動sock文件存放地址
user=mysql //mysql啓動用戶
symbolic-links=0 //關閉數據分區存儲
log-bin=/work/mysqlData/logs/mysql-bin //開啓bin-log日誌,並設置目錄
expire_logs_days = 10 //bin-log日誌存放時間爲10天
#log-slow-queries = /work/mysqlData/logs/slow.log //開啓慢查詢日誌(註釋)
#long_query_time = 1 //慢查詢日誌最大時間
log-error=error.log //錯誤日誌名稱,
max_connections = 500 //最大鏈接數
connect_timeout = 60 //鏈接保存時間
key_buffer_size = 512M //MyISAM全部緩存大小
innodb_buffer_pool_size = 1024M //Innodb緩存大小
myisam_sort_buffer_size = 256M //MyISAM排序緩存區大小
read_rnd_buffer_size = 32M //MySQL的隨機讀緩衝區大小
tmp_table_size=512M //臨時表最大值
max_heap_table_size=512M //內部臨時表的最大值
back_log = 512 //能暫存的鏈接數量
max_allowed_packet=32M //
server_id = 9 //mysql服務id
event_scheduler = ON //設定服務器端運行執行計劃任務
[mysqld_safe]
log_warnings=2 //日誌等待時間
pid-file=/var/run/mysqld/mysqld.pid //pid文件目錄
[mysql]
socket=/tmp/mysql.sock //客戶端鏈接sock文件地址
六、 初始化數據,啓動服務
/usr/local/mysql/scripts/mysql_install_db --user=mysql初始化mysql數據庫。
啓動mysql
servicemysql start
關閉mysql
servicemysql stop
七、 備份工具
安裝備份工具
tarzxf percona-xtrabackup-2.0.8-587.tar.gz
cd percona-xtrabackup-2.0.8
cp bin/innobackupex /usr/bin
cp bin/xtrabackup* /usr/bin
備份腳本
#!/bin/bash
LOG_FILE="/root/stat_data/logs/backup.log"
DATE_STR=`date '+%Y-%m-%d'`
echo "" >> $LOG_FILE
echo "" >> $LOG_FILE
echo "[`date '+%Y-%m-%d %T'`] Starting backup Mysql DB " >> $LOG_FILE
echo "===============================================" >> $LOG_FILE
echo "STEP 1 : call innobackupex [`date '+%Y-%m-%d %T'`]" >> $LOG_FILE
/usr/bin/innobackupex --user=root --password=snow436 --defaults-file=/etc/my.cnf /tmp/db_backup/ >> $LOG_FILE 2>&1
echo "-----------------------------------------------" >> $LOG_FILE
echo "STEP 2 : call tar zcf [`date '+%Y-%m-%d %T'`]" >> $LOG_FILE
DB_DIR_NAME=`ls -d /tmp/db_backup/$DATE_STR*`
GZFILE_NAME="/work/db_backup/db_full_$DATE_STR.tar.gz"
echo "Source path is : $DB_DIR_NAME Dest path is : $GZFILE_NAME" >> $LOG_FILE
/bin/tar zcf $GZFILE_NAME $DB_DIR_NAME >> $LOG_FILE 2>&1
#echo "-----------------------------------------------" >> $LOG_FILE
#echo "STEP 3 :scp to web1 [`date '+%Y-%m-%d %T'`]" >> $LOG_FILE
#REMOTE_DIR_NAME="zyx@web1:/work/backup/db_full"
#echo "Source is : $GZFILE_NAME Dest is : $REMOTE_DIR_NAME" >> $LOG_FILE
#/usr/bin/scp $GZFILE_NAME $REMOTE_DIR_NAME >> $LOG_FILE 2>&1
echo "-----------------------------------------------" >> $LOG_FILE
echo "STEP 4 : remove tmp file $DB_DIR_NAME and $GZFILE_NAME [`date '+%Y-%m-%d %T'`]" >> $LOG_FILE
rm -rf $DB_DIR_NAME >> $LOG_FILE 2>&1
#rm -f $GZFILE_NAME >> $LOG_FILE 2>&1
echo "----------------------------------------------">> $LOG_FILE
echo "delete old data back"
LAST_MONTH=`date +%Y-%m-%d --date="-2 week"`
DELETE_FILE="/work/db_backup/db_full_$LAST_MONTH.tar.gz"
if [ -f $DELETE_FILE ]
then `/bin/rm -rf $DELETE_FILE`
echo "deleted $DELETE_FILE" >> $LOG_FILE
fi
echo "===============================================" >> $LOG_FILE
echo "Finished !! [`date '+%Y-%m-%d %T'`]" >> $LOG_FILE