mysql5.7 在Centeros 6 下自动安装的shell脚本
概述:
此脚本实现了在Centeros 6版本下自动安装mysql5.7到目录 /opt/mysql-5.7*并且做软连接映射到 /usr/local/mysql,自动修改root密码为:12345678,开启root远程访问账户,此脚本yum源搭建部分请参考:Centeros 下自动区分release,连接到远程FTP yum源
讨论:
刚开始接触shell,感觉很不规范,没有进行模块区分,没有设置动态变量如密码,用户,安装目录,日志目录等等,后边会完善
脚本原文:
#!/bin/bash
rpm -qa | grep mysql | xargs rpm -e
# CenterOS config yum
osv=`rpm -q --qf %{version} centos-release`
echo "您的centeros release 版本:$osv"
echo -e "\n"
if [[ $osv -eq 6 || $osv -eq 7 ]]
then
#config yum
rm -rf /etc/yum.repos.d/*
echo "[CenterOS-source]
name=Linux "'$releasever'" - "'$basearch'" - Source
baseurl=ftp://10.0.0.1/pub/cos$osv
enabled=1
gpgcheck=0" > /etc/yum.repos.d/rhel-source.repo
yum makecache
if [ $? -gt 0 ]
then
echo "执行错误"
break
fi
echo "执行成功"
break
else
echo -e "此脚本不适配您的操作系统\n"
fi
#ulimit
ulimit -n 65535
sed -i "/soft nofile 65535/d" /etc/security/limits.conf
sed -i "/hard nofile 65535/d" /etc/security/limits.conf
echo "* soft nofile 65535
* hard nofile 65535" >> /etc/security/limits.conf
#apt-get install -y libaio*
#user and group
groupadd mysql
useradd -r -g mysql mysql
#passwd mysql
#packages
rm -rf /opt/mysql-5.7.22-linux-glibc2.12-x86_64
rm -f /usr/local/mysql/mysql-5.7.22-linux-glibc2.12-x86_64
rm -f /usr/local/mysql
cd /opt
tar zxvf $PWD/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /opt
ln -s /opt/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
mkdir /var/run/mysqld
mkdir /opt/mysql-5.7.22-linux-glibc2.12-x86_64/log
mkdir /opt/mysql-5.7.22-linux-glibc2.12-x86_64/data
chown -R mysql:mysql /var/run/mysqld
chown -R mysql:mysql /opt/mysql-5.7.22-linux-glibc2.12-x86_64
#install database
cd /usr/local/mysql/
echo "" >/usr/local/mysql/log/error.log
chown -R mysql:mysql /usr/local/mysql
chown mysql:mysql /usr/local/mysql/log/error.log
sed -i "/#mysql config/d" /etc/profile
sed -i "\/export\ PATH=\$PATH\:\/usr\/local\/mysql\/bin/d" /etc/profile
echo "#mysql config
export PATH="'$PATH'":/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
sed -i "/#mysql config/d" /root/.bashrc
sed -i "\/export\ PATH=\$PATH\:\/usr\/local\/mysql\/bin/d" /root/.bashrc
echo "#mysql config
export PATH="'$PATH'":/usr/local/mysql/bin" >> /root/.bashrc
source /root/.bashrc
mv -f /etc/my.cnf /etc/my.cnf.bak
echo "[client]
port= 3306
[mysqld]
#skip-grant-tables
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
pid-file=/var/run/mysqld/mysqld.pid
general_log=0
general_log_file=/usr/local/mysql/log/query.log
port= 3306
lower_case_table_names=1
#skip-name-resolve
character_set_server=utf8
default-storage-engine=INNODB
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
max_connections=2000
key_buffer_size = 20G
myisam_sort_buffer_size = 1280M
myisam_max_sort_file_size = 20G
myisam_repair_threads = 1
query_cache_size=5073741824
query_cache_type=1
slow-query-log=0
slow_query_log_file=/usr/local/mysql/log/slow_query.log
long_query_time=5
log-error=/usr/local/mysql/log/error.log
table_open_cache=2000
thread_cache_size=300
tmp_table_size=246M
max_heap_table_size=246M
thread_stack = 192k
key_buffer_size=512M
read_buffer_size=4M
read_rnd_buffer_size=32M
log-bin=mysql-bin
server-id=1
innodb_flush_log_at_trx_commit=2
innodb_log_buffer_size=16M
innodb_buffer_pool_size=50G
innodb_thread_concurrency=128
innodb_autoextend_increment=1000
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_log_file_size = 1G
innodb_log_files_in_group = 3
innodb_old_blocks_time=1000
innodb_open_files=1000
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log=512
flush_time=0
join_buffer_size=128M
max_allowed_packet=1024M
max_connect_errors=3000
open_files_limit=5000
sort_buffer_size=32M
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
bulk_insert_buffer_size = 64M
log_timestamps=SYSTEM
log_error_verbosity=2" > /etc/my.cnf
mv -f /etc/init.d/mysqld /etc/init.d/mysqld.bak
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
#vi /etc/init.d/mysqld
# 46行 basedir=/usr/local/mysql datadir=/usr/local/mysql/data
sed -i '46s/basedir\=/basedir\=\/usr\/local\/mysql/g' /etc/init.d/mysqld
sed -i '47s/datadir\=/datadir\=\/usr\/local\/mysql\/data/g' /etc/init.d/mysqld
pkill -9 mysql
rm -rf /usr/local/mysql/data/*
echo "" > /usr/local/mysql/log/error.log
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
#sleep 1
/etc/init.d/mysqld start
ps -ef | grep mysql
#defaultmysqlpwd=`grep 'A temporary password' /usr/local/mysql/log/error.log | awk -F"root@localhost: " '{ print $2}' `
#echo $defaultmysqlpwd
sleep 10
ps -ef | grep mysql
mysqladmin -uroot password 12345678
mysql -uroot -p12345678 <<EOF
grant all privileges on *.* to root@'%' identified by '12345678';flush privileges;
EOF
mysql -uroot -p12345678
mysql5.7 在Centeros 6 下自动安装的shell脚本的更多相关文章
- CentOS 下运维自动化 Shell 脚本之 expect
CentOS 下运维自动化 Shell脚本之expect 一.预备知识: 1.在 Terminal 中反斜杠,即 "" 代表转义符,或称逃脱符.("echo -e与pri ...
- linux系统下重启tomcat的shell脚本
linux系统下重启tomcat的shell脚本: #!/bin/shtomcat_home=/opt/apache-tomcat- #找到tomcat进程的id并kill掉 ps -ef |grep ...
- top 自动执行的shell脚本中,使用top -n 1 > log.txt, 上电自动执行,文件无输出
. 自动执行的shell脚本中,使用top -n > log.txt, 上电自动执行,文件无输出,使用一下命令解决: //usr/bin/top -d -n -b > log.txt 如果 ...
- mysql-5.7.xx在lcentos7下的安装以及mysql在windows以及linux上的性能差异
前言: 在centos上安装mysql,整整折腾了将近一天,因为是第一次安装,的确是踩了不少坑,这里详细记录下来,方便各位有同样需求的小伙伴参考. 该选择什么版本? mysql5.7有很多小版本,但是 ...
- 一个简单的linux下设置定时执行shell脚本的示例
很多时候我们有希望服务器定时去运行一个脚本来触发一个操作,比如说定时去备份服务器数据.数据库数据等 不适合人工经常做的一些操作这里简单说下 shell Shell俗称壳,类似于DOS下的command ...
- Ubuntu 设定壁纸自动切换的shell脚本
升级到Ubuntu14.04后,感觉bug的确比12.04少多了.顶部任务栏支持半透明效果,所以整个桌面也看上去漂亮了很多.这样的桌面也是值得瞎捣鼓一下的,想到换壁纸,但是没找到设定动态更换壁纸的选项 ...
- Centos下使用php调用shell脚本
我们在实际项目中或许会遇到php调用shell脚本的需求.下面就用简单案例在Centos环境下实践 准备 查看php.ini中配置是否打开安全模式 //php.ini safe_mode = //这个 ...
- mysql5.5.28在Linux下的安装
1. 下载mysql 在http://dev.mysql.com/downloads/mysql/ 官网上下载mysql-5.5.28-linux2.6-i686.tar.gz. 2. ...
- Java web项目在linux环境下自动编译和部署脚本
自动编译脚本 build.sh, 放置在项目根目录下. #!/bin/bash # check args # init path CURRPATH=`pwd` LIBDIR="$CURRPA ...
随机推荐
- hdoj【1006】【未完待续】
题意: 时钟的三个指针在两两之间至少D°的时候是开心的,求开心时间占一天的一个百分比. 思路: 我们看到这个百分比有三位小数,精度很高. 一天有24h,24*60min,24*60*60s,那么最小单 ...
- poj 1182 食物链【带权并查集】
设相等的边权为0,吃的边权为,被吃的边权为2,然后用带权并查集在%3的意义下做加法即可 关系为简单环的基本都可以用模环长的方式是用带权并查集 #include<iostream> #inc ...
- PAT团体程序设计天梯赛 - 模拟赛
由于本人愚笨,最后一题实在无力AC,于是只有前14题的题解Orz 总的来说,这次模拟赛的题目不算难,前14题基本上一眼就有思路,但是某些题写起来确实不太容易,编码复杂度有点高~ L1-1 N个数求和 ...
- CSS3向上移动的效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- IDEA中创建HBASE工程
IntelliJ IDEA+maven的HBase开发环境搭建 hbase 配置(hbase-site.xml)和基本使用 16010端口可以查看Hbase web信息
- Codeforces Round #395 (Div. 2) D
Description One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On t ...
- Mysql查询语句的 where子句、group by子句、having子句、order by子句、limit子句
Mysql的各个查询语句 一.where子句 语法:select *|字段列表 from 表名 where 表达式.where子句后面往往配合MySQL运算符一起使用(做条件判断) 作用:通过限定 ...
- 香港药品 ref
--公牛牌风湿骨刺丹30粒 参考网站--http://item.jd.com/1955815605.html?gjz=0#comments-list 88 --参考网站1,没有 http://www. ...
- 476 Number Complement 数字的补数
给定一个正整数,输出它的补数.补数是对该数的二进制表示取反.注意: 给定的整数保证在32位带符号整数的范围内. 你可以假定二进制数不包含前导零位.示例 1:输入: 5输出: 2解释: 5的 ...
- eclipse导入php项目
整个工程的都在一个文件夹里面 怎么把它导入到eclipse里面呢:在eclipse里新建一个与要导入的工程同名工程.