标签:my.cnf evel eof 比较 sql sed pac 字符 行记录
#!/bin/bash#安装编译代码需要的包
/usr/bin/yum -y install make wget gcc-c++ cmake bison-devel ncurses-devel libaio
echo "============================Install MySQL 5.7.22=================================="
#编译安装mysql5.7.22
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql -M -s /sbin/nologin
#下载MySQL安装的版本
cd /opt/ && rm -rf /usr/local/mysql
wget -c https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
/bin/tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
cd /usr/local/ && mv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
#配置my.cnf
cat > /etc/my.cnf << EOF
[mysqld]
#服务端设置
skip-name-resolve
#设置3306端口
port = 3306
socket=/var/lib/mysql/mysql.sock
basedir=/usr/local/mysql
datadir=/data/app
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB
#表名存储在磁盘是小写的,但是比较的时候是不区分大小写
lower_case_table_names=1
#限制server接受的数据包大小
max_allowed_packet=20M
#slow_query_log=on
#log
log-error=/usr/local/mysql/log/error.log
#log=/usr/local/mysql/log/mysql.log
#long_query_time=2
#将查询返回较慢的语句进行记录
#log-slow-queries= /usr/local/mysql/log/slowquery.log
#log-update=/var/lib/mysql/update.log
[mysql]
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
#mysql配置-在zabbix agent上操作
##添加帐户登录信息等,以便zabbix监控
#添加以下内容(账户密码自己设置)
#user = mysqlcheck
#password = chechk
#[client]
#user = check
#password = chechk
#[mysqladmin]
#user = check
#password = chechk
EOF
#启动mysql服务
cd /usr/local/
/bin/mkdir -p /data/app
/bin/mkdir -p /usr/local/mysql/log/
/bin/chown -R mysql.mysql /usr/local/mysql
/bin/chown -R mysql.mysql /data
cd /data/app/ && rm -rf *
echo "===================================== 初始化及配置 ==================================="
cd /usr/local/mysql/
./bin/mysqld --defaults-file=/etc/my.cnf --initialize
#到此数据库安装完毕!
/bin/chmod 755 /etc/my.cnf
/bin/mkdir -p /var/lib/mysql/
/bin/chown -R mysql:mysql /var/lib/mysql/
/bin/chown -R mysql:mysql /data/
/bin/chown -R mysql:mysql /usr/local/mysql
#设置开机自启动服务控制脚本
cp ./support-files/mysql.server /etc/rc.d/init.d/mysql
/bin/chmod +x /etc/rc.d/init.d/mysql
chkconfig --add mysql
#将mysql的bin目录加入PATH环境变量
cat >> /etc/profile <<EOF
export PATH=$PATH:/usr/local/mysql/bin
EOF
#启动msql
#查看状态
ps -ef|grep mysql
/sbin/chkconfig mysql on
/bin/chown -R mysql:mysql /data/
cd /etc/init.d && chmod +x mysql
/etc/init.d/mysql start
echo "===================================== 查看数据库状态 ==================================="
ps -ef|grep mysql && netstat -tunpl
echo "===================================== 修改密码设置权限 ==================================="
#设置mysql登陆密码,密码为a123456
for i in grep ‘temporary password‘ /usr/local/mysql/log/error.log|awk ‘NR==1{print}‘|awk -F: ‘{print $NF}‘
;
do
mysql -uroot -p$i -e "SET PASSWORD FOR ‘root‘@‘localhost‘ = PASSWORD(‘a123456‘);" -b --connect-expired-password
#设置远程主机登录,注意:如果是生产环境不介意开启root远程登陆(安全问题)
mysql -uroot -p‘a123456‘ -e "GRANT ALL PRIVILEGES ON . TO ‘root‘@‘%‘ IDENTIFIED BY ‘a123456‘ WITH GRANT OPTION;"
mysql -uroot -p‘a123456‘ -e "FLUSH PRIVILEGES;"
done
echo "===================================== 重启MySQL ==================================="
/etc/init.d/mysql restart
标签:my.cnf evel eof 比较 sql sed pac 字符 行记录
原文地址:http://blog.51cto.com/10158955/2150573