MySQL学习笔记(一):shell脚本安装配置mysql-创新互联
该脚本用于MySQL二进制安装,仅限于最初安装,如服务器已安装配置有mysql,不建议使用该脚本。
成都创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站设计、成都网站制作、诸城网络推广、小程序开发、诸城网络营销、诸城企业策划、诸城品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们大的嘉奖;成都创新互联为所有大学生创业者提供诸城建站搭建服务,24小时服务热线:028-86922220,官方网址:www.cdcxhl.com操作系统版本:CentOS 7
数据库版本:MySQL 5.7.22
#!/bin/bash cnf_file="/etc/my.cnf" install_log="mysql_install.log" dbfile="mysql-5.7.22-el7-x86_64.tar.gz" ext_files="mysql-5.7.22-el7-x86_64" bin_path="/usr/local/mysql" pid_path="/data/mysql" data_path="/data/mysql/data" errlog_path="/data/mysql/logs/" binlog_path="/data/mysql/binlog/" slowlog_path="/data/mysql/slow_logs" socket="/data/mysql/mysql3306.sock" port=3306 serverid=330601 group="mysql" user="mysql" if [ ! -f "$dbfile" ];then echo "$dbfile not exists" > $install_log else tar -zxvf $dbfile > $install_log if [ $? -eq 0 ];then echo "$dbfile Extract Success" >> $install_log else echo "$dbfile Extract Failed" >> $install_log exit 0 fi fi if [ ! -d "$bin_path" ];then echo "moving $ext_files to $bin_path ......" >> $install_log mv $ext_files $bin_path echo "move $ext_files to $bin_path ......[done]" >> $install_log echo "creating $pid_path ......" >> $install_log if [ ! -d "$pid_path" ];then mkdir -p $pid_path echo "create $pid_path ......[done]" >> $install_log else echo "create $pid_path ......[failed]" >> $install_log exit 0 fi echo "creating $data_path ......" >> $install_log if [ ! -d "$data_path" ];then mkdir -p $data_path echo "create $data_path ......[done]" >> $install_log else echo "create $data_path ......[failed]" >> $install_log exit 0 fi echo "creating $errlog_path ......" >> $install_log if [ ! -d "$errlog_path" ];then mkdir -p $errlog_path echo "create $errlog_path ......[done]" >> $install_log else echo "create $errlog_path ......[failed]" >> $install_log exit 0 fi echo "creating $binlog_path ......" >> $install_log if [ ! -d "$binlog_path" ];then mkdir -p $binlog_path echo "create $binlog_path ......[done]" >> $install_log else echo "create $binlog_path ......[failed]" >> $install_log exit 0 fi echo "creating $slowlog_path ......" >> $install_log if [ ! -d "$slowlog_path" ];then mkdir -p $slowlog_path echo "create $slowlog_path ......[done]" >> $install_log else echo "create $slowlog_path ......[failed]" >> $install_log exit 0 fi else echo "$bin_path already exists" >> $install_log exit 0 fi #create group if not exists egrep "^$group" /etc/group >& /dev/null if [ $? -ne 0 ] then echo "group $group not exists" >> $install_log echo "creating group $group ......" >> $install_log groupadd $group echo "creat group $group ......[done]" >> $install_log else echo "group $group already exists ......[skip]" >> $install_log fi #create user if not exists egrep "^$user" /etc/passwd >& /dev/null if [ $? -ne 0 ] then echo "user $user not exists" >> $install_log echo "creating user $user ......" >> $install_log useradd -g $group $user echo "creat user $user ......[done]" >> $install_log else echo "user $user already exists ......[skip]" >> $install_log fi #Modify directory permissions chown -R $user.$group $bin_path chown -R $user.$group $pid_path #Add environment variables result_grep_path="$( grep "${bin_path}/bin" /etc/profile )" || result_grep_path="" if [ -z "${result_grep_path}" ] then echo "export PATH=\$PATH:${bin_path}/bin:${bin_path}/lib" >> /etc/profile ; source /etc/profile else echo "${bin_path}/bin already exists in /etc/profile" >> $install_log fi #mysql cnf if [ -f $cnf_file ];then echo "$cnf_file exists" echo "move $cnf_file to $cnf_file`date '+%Y%m%d%H%M%S'` " >> $install_log mv $cnf_file $cnf_file`date "+%Y%m%d%H%M%S"` fi cat > /etc/my.cnf << EOF [mysql] socket=${socket} [mysqld] server_id=${serverid} user=mysql socket=${socket} port=${port} basedir=${bin_path} datadir=${data_path} log_bin=${binlog_path}/mysql01_bin.log log_error=${errlog_path}/mysql_err.log slow_query_log = on long_query_time = 2 slow_query_log_file = ${slowlog_path}/mysql_slow.log EOF mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize if [ $? -eq 0 ]; then echo "mysql initialize success ">> $install_log else echo "mysql initialize failed ">> $install_log exit 0 fi cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql.server chmod +x /etc/rc.d/init.d/mysql.server chkconfig --add mysql.server chkconfig --list mysql.server >> $install_log sudo -u mysql service mysql.server start if [ $? -eq 0 ]; then echo "mysql install && start success ">> $install_log else echo "mysql install or start failed">> $install_log fi exit 0另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网页名称:MySQL学习笔记(一):shell脚本安装配置mysql-创新互联
分享网址:http://pwwzsj.com/article/deghdj.html