mysql 5 二进制版本安装
使用如下脚本,直接安装即可
mysql版本:mysql-5.0.96-linux-x86_64-glibc23.tar.gz
备份工具:percona-xtrabackup-2.0.8-587.tar.gz
1 #!/bin/bash 2 INSTALL_DIR="/xxxx/mysqldata" 3 MYSQL_PORT="3306" 4 MYSQL_LOG="/xxxx/mlogs" 5 SERVER_ID="360" 6 7 echo "##################下载mysql-5.0.96-linux安装包###################" 8 wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.0.96-linux-x86_64-glibc23.tar.gz 9 wget http://www.percona.com/downloads/XtraBackup/XtraBackup-2.0.8/binary/Linux/x86_64/percona-xtrabackup-2.0.8-587.tar.gz 10 11 echo "##########################基础环境安装配置########################" 12 echo "安装目录为: ${INSTALL_DIR}" 13 echo "数据库使用的端口为: ${MYSQL_PORT}" 14 echo "数据库的日志目录在: ${MYSQL_LOG}" 15 echo "数据库的id(主从同步时使用,数据库主从集群唯一即可): ${SERVER_ID}" 16 echo "########################## 开始进入安装 #########################" 17 mkdir -p ${MYSQL_LOG}/mysql${MYSQL_PORT} 18 mkdir -p ${INSTALL_DIR}/mysql${MYSQL_PORT} 19 mkdir -p ${INSTALL_DIR}/mysql${MYSQL_PORT}/{data,run,conf,logbin,tmp,shell,relaylog,backup} 20 tar -xf mysql-5.0.96-linux-x86_64-glibc23.tar.gz -C ${INSTALL_DIR}/mysql${MYSQL_PORT}/ 21 tar -xf percona-xtrabackup-2.0.8-587.tar.gz -C ${INSTALL_DIR}/mysql${MYSQL_PORT}/ 22 cd ${INSTALL_DIR}/mysql${MYSQL_PORT}/ 23 mv mysql-5.0.96-linux-x86_64-glibc23 mysql_server 24 mv percona-xtrabackup-2.0.8 xtrabackup 25 cp ${INSTALL_DIR}/mysql${MYSQL_PORT}/mysql_server/share/mysql/english/errmsg.sys ${INSTALL_DIR}/mysql${MYSQL_PORT}/mysql_server/share/ 26 27 28 echo """[client] 29 port=${MYSQL_PORT} 30 default-character-set=utf8 31 socket=${INSTALL_DIR}/mysql${MYSQL_PORT}/run/mysql${MYSQL_PORT}.sock 32 33 [mysqld] 34 log-error=${MYSQL_LOG}/mysql${MYSQL_PORT}/mysqld${MYSQL_PORT}.log 35 datadir=${INSTALL_DIR}/mysql${MYSQL_PORT}/data 36 basedir=${INSTALL_DIR}/mysql${MYSQL_PORT}/mysql_server 37 default-character-set=utf8 38 max_connections=500 39 interactive_timeout=310000 40 wait_timeout=31000 41 query_cache_size=48M 42 table_cache=320 43 tmp_table_size=52M 44 thread_cache_size=8 45 sort_buffer_size=256K 46 innodb_thread_concurrency=8 47 myisam-recover=FORCE 48 max_allowed_packet=32M 49 innodb_file_per_table=1 50 server_id=${SERVER_ID} 51 max_binlog_size=1G 52 log_bin=${INSTALL_DIR}/mysql${MYSQL_PORT}/logbin/mysql-bin-${MYSQL_PORT} 53 expire_logs_days=14 54 port=${MYSQL_PORT} 55 socket=${INSTALL_DIR}/mysql${MYSQL_PORT}/run/mysql${MYSQL_PORT}.sock 56 pid-file=${INSTALL_DIR}/mysql${MYSQL_PORT}/run/mysqld${MYSQL_PORT}.pid 57 #lc-messages-dir=${INSTALL_DIR}/mysql${MYSQL_PORT}/mysql_server/share/mysql/english 58 relay_log_purge=1 59 relay-log=${INSTALL_DIR}/mysql${MYSQL_PORT}/relaylog/relay-bin-${MYSQL_PORT} 60 relay-log-index=${INSTALL_DIR}/mysql${MYSQL_PORT}/relaylog/relay-bin-${MYSQL_PORT}.index 61 62 [xtrabackup] 63 socket=${INSTALL_DIR}/mysql${MYSQL_PORT}/run/mysql${MYSQL_PORT}.sock""" >> ${INSTALL_DIR}/mysql${MYSQL_PORT}/conf/my${MYSQL_PORT}.cnf 64 65 66 echo "授权操作" 67 chown -R mysql:mysql ${MYSQL_LOG}/mysql${MYSQL_PORT} 68 chown -R mysql:mysql ${INSTALL_DIR}/mysql${MYSQL_PORT} 69 70 71 echo "数据库初始化操作" 72 ${INSTALL_DIR}/mysql${MYSQL_PORT}/mysql_server/scripts/mysql_install_db --defaults-file=${INSTALL_DIR}/mysql${MYSQL_PORT}/conf/my${MYSQL_PORT}.cnf --basedir=${INSTALL_DIR}/mysql${MYSQL_PORT}/mysql_server --datadir=${INSTALL_DIR}/mysql${MYSQL_PORT}/data --user=mysql >> ${MYSQL_LOG}/mysql${MYSQL_PORT}/mysql-primary-${MYSQL_PORT}.logs 2>&1 73 chown -R mysql:mysql ${INSTALL_DIR}/mysql${MYSQL_PORT} 74 75 76 echo "数据库启动脚本" 77 echo "${INSTALL_DIR}/mysql${MYSQL_PORT}/mysql_server/bin/mysqld --defaults-file=${INSTALL_DIR}/mysql${MYSQL_PORT}/conf/my${MYSQL_PORT}.cnf --basedir=${INSTALL_DIR}/mysql${MYSQL_PORT}/mysql_server --datadir=${INSTALL_DIR}/mysql${MYSQL_PORT}/data --user=mysql >> ${MYSQL_LOG}/mysql${MYSQL_PORT}/mysql-${MYSQL_PORT}.logs 2>&1 &" >> ${INSTALL_DIR}/mysql${MYSQL_PORT}/shell/start.sh 78 79 80 echo "数据库关闭脚本" 81 echo "${INSTALL_DIR}/mysql${MYSQL_PORT}/mysql_server/bin/mysqladmin shutdown --user=root --password='' --socket=${INSTALL_DIR}/mysql${MYSQL_PORT}/run/mysql${MYSQL_PORT}.sock" >> ${INSTALL_DIR}/mysql${MYSQL_PORT}/shell/stoppid.sh 82 83 echo "进入mysql脚本" 84 echo "${INSTALL_DIR}/mysql${MYSQL_PORT}/mysql_server/bin/mysql -uroot -p'' -S ${INSTALL_DIR}/mysql${MYSQL_PORT}/run/mysql${MYSQL_PORT}.sock" >> ${INSTALL_DIR}/mysql${MYSQL_PORT}/shell/insert.sh 85 86 echo "其它操作" 87 echo """ 88 #授权 89 grant all on *.* to xxxx@'x.x.x.%' identified by 'xxxxxx'; 90 #检查用户 91 select Host,User,Password from mysql.user; 92 #设置主从同步权限(主库操作即可) 93 grant all privileges on *.* 'xxxx'@'x.x.x.%' identified by 'xxxxxx'; 94 flush privileges; 95 #检查某用户权限 96 SHOW GRANTS FOR 'xxxx'@'x.x.x.%'; 97 #备份工具 98 ${MYSQL_LOG}/mysql${MYSQL_PORT}/xtrabackup/bin/innobackupex 99 #帮助信息 100 ${INSTALL_DIR}/mysql${MYSQL_PORT}/mysql_server/bin/mysqld --defaults-file=${INSTALL_DIR}/mysql${MYSQL_PORT}/conf/my${MYSQL_PORT}.cnf --verbose --help 101 """ 102 103 echo "mysql-5.0.96安装完成"