Steward_Xu

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

一:readme:

1 1、此脚本仅仅适合于5.7免面编译安装版本。
2 2、安装是需自己选择mysql软件安装包:例如mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz或者mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz;请选择glibc版及免编译版本。
3 3、此脚本可选择自动下载和手动上传安装软件包进行安装。
4 选择自动下载安装请提前获取下载地址并根据提示输入下载URL;如选择手动上传需提前下载好软件包并确认系统中有lrzsz包。
5 4.安装过程中需要手动输入安装路径以及mysql数据存储路径,请提前规划好。也可根据提示输入路径。。
6 5安装完成后请注意提示,因为脚本会输出此次安装后的登录密码,请记住登录密码。可使用/etc/init.d/mysqld start|stop|restart进行启停。启动后请使用所给的登录密码登录(每次安装登录密码随机)。
View Code

二:脚本代码:

  1 #!/bin/sh
  2 ##########################################
  3 # this script is created by xuxuedong.   #
  4 # e_mail:365***746@qq.com                #
  5 # qqinfo:365***746                       #
  6 # This is install Mysql5.7               #
  7 # version:1.1                            #
  8 ##########################################
  9 . /etc/init.d/functions
 10 #set env
 11 export PATH=$PATH:/bin:/sbin:/usr/sbin
 12 export LANG="zh_CN.GB18030"
 13 packge=/home/admin/tools
 14 
 15 
 16 # Require root to run this script.  判断是否是root用户执行。
 17 #if [[ "$(whoami)" != "root" ]]; then
 18 #        echo "Please run this script as root." >&2
 19 #        exit 1
 20 #fi
 21 #Show users how to install.让用户选择如何安装
 22 menu ( ){  
 23 
 24 cat<<END
 25         1.手动上传安装
 26         2.网络下载安装
 27         3.[exit]
 28         pls input the num that you want:
 29 END
 30 
 31 }
 32 menu
 33 read num
 34 echo "you choice $num"
 35 #upload the packge by user 用户自己上传安装文件
 36 function upload(){
 37         if [  -e $packge ]
 38                 then
 39                         cd ${packge}&rz
 40                 else
 41                         mkdir -p ${packge}&cd ${packge}&rz
 42         fi
 43         if [ $? -eq 0 ]
 44                 then 
 45                         action "THE sofeware is upload to ${packge}"  /bin/true
 46                 else
 47                         action "THE sofeware is upload fail"  /bin/false
 48         fi
 49 }
 50 ###############################
 51 #donwload the packge from URL 用户自己输入下载路径
 52 function WGET(){
 53         while True
 54                 do
 55                 if [  -e $packge ]
 56                         then
 57                                 cd ${packge}
 58                                 read -p "input donwload URL:" URL
 59                                 if [$URL != z ]
 60                                         then 
 61                                                 wget $URL
 62                                                 if [ $? -eq 0 ]
 63                                                         then 
 64                                                                 action "THE sofeware is download to ${packge}"  /bin/true
 65                                                                 break
 66                                                         else
 67                                                                 Continue
 68                                                 fi
 69                                         else
 70                                                 mkdir -p ${packge}&cd ${packge}
 71                                  fi
 72                 fi
 73         done
 74                 if [ $? -eq 0 ]
 75                         then 
 76                                 action "THE sofeware is upload to ${packge}"  /bin/true
 77                         else
 78                                 action "THE sofeware is upload fail"  /bin/false
 79                 fi
 80 }
 81 ########################
 82 ##install Mysql 自动安装  可用while循环实现只有输入目录才能执行
 83 function InsTall(){
 84         read -p "input a installdir for install mysql(example /application/newmysql):"  installdir
 85                 if [ -e $installdir ]
 86                     then 
 87                         action "THE dir is exist"  /bin/true
 88                     else 
 89                         mkdir -p $installdir
 90                 fi
 91         #       Installdir = $installdir
 92         read -p "input a mysqldata_dir for mysql_data(example /application/newmysql/3306data):"  mysqldata_dir
 93                 if [ -e $mysqldata_dir ]
 94                     then
 95                         action "THE dir is exist"  /bin/true
 96                     else
 97                         mkdir -p $mysqldata_dir
 98                 fi
 99         #       Mysqldata_dir = $mysqldata_dir
100         cd ${packge}
101         echo "`ls -l mysql*`"
102         read -p "please input you want to install version:" ver
103                 tar -zxf $ver -C $installdir
104         cd $installdir 
105         echo "`ls -l `"
106         read -p "please input you want to install version:" installroot_dir
107                 rm -rf  ${mysqldata_dir}/*
108                 ${installroot_dir}/bin/mysqld --initialize  --basedir=${installdir} --datadir=${mysqldata_dir}
109                 if [ $? -eq 0  ]
110                     then 
111                         action "mysql is install initialize"  /bin/true
112                     else 
113                         action "mysql is install initialize false"  /bin/false
114                         exit
115                 fi
116                 ln -s ${installroot_dir}/bin  $installdir/bin
117                 cp ${installroot_dir}/support-files/mysql.server /etc/init.d/mysqld
118                 cp ${installroot_dir}/support-files/my-default.cnf /etc/my.cnf
119                 cat >>/etc/my.cnf <<EOF
120         [client]
121         port=3306
122         user=iddbs
123         password ='newpassword'
124         socket=${mysqldata_dir}/mysql.sock 
125         [mysqld]
126         max_connections=1000
127         max_user_connections=500
128         wait_timeout=200
129         user=iddbs
130         server-id=5
131         port=3306
132         basedir=$installdir
133         datadir=${mysqldata_dir}
134         socket=${mysqldata_dir}/mysql.sock
135         pid-file=${mysqldata_dir}/mysql.pid
136         log-bin=${mysqldata_dir}/mysql-bin
137         relay-log=${mysqldata_dir}/relay-bin
138         log-error=${mysqldata_dir}/mysql-error.log
139         interactive_timeout=172800
140         wait_timeout=172800
141         max_allowed_packet=16M
142         expire_logs_days=7
143         auto-increment-increment=2
144         auto-increment-offset=1
145         character-set-server=utf8
146         collation_server=utf8_general_ci
147         innodb_data_file_path=ibdata1:1G:autoextend
148         innodb-buffer-pool-size=15G
149         binlog_format=row
150         relay_log_recovery=1
151         log_bin_trust_function_creators=1
152         # Disabling symbolic-links is recommended to prevent assorted security risks
153         symbolic-links=0
154         lower_case_table_names = 1
155         character_set_server = utf8
156         event_scheduler = on
157         [mysqldump]
158         quick
159         max_allowed_packet = 16M
160 
161         [mysql]
162         no-auto-rehash
163         # Remove the next comment character if you are not familiar with SQL
164         #safe-updates
165         default-character-set = utf8
166 
167         [myisamchk]
168         key_buffer_size = 512M
169         sort_buffer_size = 512M
170         read_buffer = 8M
171         write_buffer = 8M
172 EOF
173 
174         echo "export PATH=$PATH:${installdir}/bin">>/etc/profile
175         source /etc/profile
176         echo "mysql login password for root is:`cat ${mysqldata_dir}/mysql-error.log  | grep password`"
177 }
178 function quit(){
179     if [ "$num" -eq 3 ]
180         then                        
181             echo "logout..."
182             exit 0
183     fi    
184 }
185 
186 case $num in
187         1)
188         upload
189                 InsTall
190 ;;
191         2)
192         WGET
193                 InsTall
194 ;;
195         3)
196         quit
197 ;;
198 
199         *)
200         echo "USAG:1|2|3"
201 esac 
View Code

三:完成登录数据库后操作:

  由于mysql5.7基于安全考虑对于通过第一次安装密码进行登录后,无法进行操作的问题(不能查看库、表等):

  请点击此处

 

posted on 2017-06-19 15:39  Steward_Xu  阅读(276)  评论(0编辑  收藏  举报