Centos6.5 编译安装Mysql 5.5.3.7
Posted QY_大师兄
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos6.5 编译安装Mysql 5.5.3.7相关的知识,希望对你有一定的参考价值。
1、准备依赖包
yum install gcc* c++ * bison autoconfautomakezlib* libxml* ncurses-devellibmcrypt* libtool-ltdl-devel*
yum install cmake*
2、添加mysql用户和用户组
groupadd mysql
useradd -s /sbin/nologin -g mysql
3、创建数组存放目录
Mkdir–R /work/mysqlData
给mysql权限
Chown–R mysql.mysql/work/mysqlData
4、编译安装
解压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文件地址
6、初始化数据,启动服务
/usr/local/mysql/scripts/mysql_install_db --user=mysql初始化mysql数据库。
启动mysql
servicemysql start
关闭mysql
servicemysql stop
7、备份工具
安装备份工具
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="[email protected]:/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 [email protected]‘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;
1、 准备依赖包
yum install gcc* c++ * bison autoconfautomakezlib* libxml* ncurses-devellibmcrypt* libtool-ltdl-devel*
yum install cmake*
2、 添加mysql用户和用户组
groupaddmysql
useradd -s /sbin/nologin -g mysql
3、 创建数组存放目录
Mkdir–R /work/mysqlData
给mysql权限
Chown–R mysql.mysql/work/mysqlData
4、 编译安装
解压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文件地址
6、初始化数据,启动服务
/usr/local/mysql/scripts/mysql_install_db --user=mysql初始化mysql数据库。
启动mysql
servicemysql start
关闭mysql
servicemysql stop
7、备份工具
安装备份工具
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="[email protected]:/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
以上是关于Centos6.5 编译安装Mysql 5.5.3.7的主要内容,如果未能解决你的问题,请参考以下文章
CentOS6.5一键安装MySQL5.5.32(源码编译)