-
Notifications
You must be signed in to change notification settings - Fork 16
/
MySQL_install.sh
872 lines (820 loc) · 22.8 KB
/
MySQL_install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
#!/bin/bash
####################
### MySQL5.7版本 ####
### CentOS7.x版本 ###
####################
#####Install Failed Delete MySQL#####
#####rm -rf $base/*
#####rm -rf $data/*
#####rm -rf /etc/init.d/mysqld
#####rm -rf /usr/local/mysql
clear
#check /etc/hosts
echo "Check /etc/hosts"
hostname=`hostname`
host=`cat /etc/hosts|grep $hostname`
if [ -z "$host" ];then
echo 'check /etc/hosts IP hostname Failed!'
exit 0
else
echo 'check /etc/hosts IP hostname success!'
rehost=`echo $host|awk '{print $1}'`
id1=`echo ${rehost#*.}`
id2=`echo ${id1#*.}`
id=`echo $id2|sed 's/\.//g'`
##check memory
mem=`grep MemTotal /proc/meminfo|awk '{print $2}'`
let innobufsiz=$mem*7/10/1024
let mem=$mem/1024
echo " "
echo "##########################################"
echo "# 1,Default Quick Install #"
echo "# 2,Custom Install #"
echo "# 3,Cancel Install #"
echo "# Version:MySQL 5.7.18 #"
echo "##########################################"
echo " "
#####please input : 1,Default Install 2,Custom Install 3,Cancel Install#######
read -p "Please Select [1-3] To Continue (Default 1): " which
which=${which:=1}
while true
do
case "$which" in
1)
################Default Quick Install################
##Define variables
port=3306
base='/mysql/mysoft'
data='/mysql/mydata'
ser_id=$id
char='utf8'
innodb=$innobufsiz
azlj=`pwd`
##create user
usero=`id mysql|awk '{print $1}'`
if [ -z "$usero" ];then
/usr/sbin/groupadd -g 600 mysql
/usr/sbin/useradd -u 600 -g mysql mysql
echo mysql | passwd mysql --stdin 1>/dev/null
echo ""
id mysql
echo ""
else
echo ""
id mysql
echo ""
echo -n "Do you want to use users (mysql) ("no" delet user and rebuild)[y|n] (Default y): "
read cho
cho=${cho:='y'}
echo ""
while true
do
case $cho in
N|NO|n|no)
/usr/sbin/userdel -r mysql 2>/dev/null
/usr/sbin/groupdel mysql 2>/dev/null
/usr/sbin/groupadd -g 600 mysql
/usr/sbin/useradd -u 600 -g mysql mysql
echo mysql | passwd mysql --stdin 1>/dev/null
id mysql
echo ""
break
;;
Y|YES|y|yes)
id mysql
echo mysql | passwd mysql --stdin 1>/dev/null
echo ""
break
;;
exit|EXIT)
exit
break
;;
*)
echo -n "Do you want to use users (mysql) ("no" delet user and rebuild)[y|n] (Default y): "
read cho
cho=${cho:='y'}
echo ""
;;
esac
done
fi
####################os check####################
echo "Check $base and $data"
mysql=`df -hm| grep -w $base | awk '{print $(NF-2)}'`
if [ ! -n "$mysql" ];then
echo "$base not have lv"
if [ ! -d "$base" ];then
echo "$base dose not exist;"
echo -n "please press y to create $base,n to quit (Y/N) (Default Y): "
read cho
cho=${cho:='y'}
echo ""
while true
do
case $cho in
N|NO|n|no)
echo "Please create $base !!!"
echo ""
exit
;;
Y|YES|y|yes)
mkdir -p $base
break
;;
esac
done
fi
else
if [ "$mysql" -lt 29000 ];then
echo '$base lv must >=30G'
fi
fi
mydata=`df -hm| grep -w $data | awk '{print $(NF-2)}'`
if [ ! -n "$mydata" ];then
echo "$data not have lv"
if [ ! -d "$data" ];then
echo "$data dose not exist;"
echo -n "please press y to create $data,n to quit (Y/N) (Default Y): "
read cho
cho=${cho:='y'}
echo ""
while true
do
case $cho in
N|NO|n|no)
echo "Please create $data !!!"
echo ""
exit
;;
Y|YES|y|yes)
mkdir -p $data
break
;;
esac
done
fi
else
if [ "$mydata" -lt 99000 ];then
echo '$data lv must >=100G'
fi
fi
echo " "
##osversion
os=`lsb_release -a|grep Description`
v_version=`echo ${os#*:}`
##check old mysql
echo "Check Old Mysql"
rpm=`rpm -qa | grep mysql`
if [ -z "$rpm" ];then
echo "check old mysql success!"
else
rpm -e $rpm --nodeps
echo "check old mysql: $rpm delete success!"
fi
echo " "
##print message
echo "|--------------------------------------------------------------------|"
echo " Os Version: $v_version "
echo " MemTotal: $mem M "
echo " BaseDir: $base "
echo " DataDir: $data/$port "
echo " Port : $port "
echo " Server Id: $ser_id "
echo " Defalut Character: $char "
echo " Innodb_buffer_pool_size: $innodb M "
echo " Host Ipaddr: $rehost "
echo "|--------------------------------------------------------------------|"
echo " "
echo -n "please press y to continue,n to quit (Y/N) (Default Y): "
read cho
cho=${cho:='y'}
echo ""
while true
do
case $cho in
N|NO|n|no)
echo "Thanks!"
echo ""
break
;;
Y|YES|y|yes)
##new directory
mkdir -p $data/$port/data
mkdir -p $data/$port/log
mkdir -p $data/$port/binlog
mkdir -p $data/$port/tmp
##edit limits.conf
cat >>/etc/security/limits.conf << END
mysql hard nofile 65535
mysql soft nofile 65535
END
##edit .bash_profile
PROFILES="/home/mysql/.bash_profile"
for PROFILE in $PROFILES ; do
if [ -f "$PROFILE" ] ; then
if [ -z "$(grep "MySQL" $PROFILE)" ] ; then
cat >>$PROFILE << END
#MySQL
export MYSQL_HOME=$base
export PATH=\$MYSQL_HOME/mysql5.7/bin:\$PATH
END
echo "$PROFILE parameters : success"
else
echo "$PROFILE parameters : already existed"
fi
else
echo "$0: $PROFILE not found "
fi
done
##install software
cd $azlj
tar -xf mysql*5.7*tar* -C $base
cd $base
tar xf mysql-5.7*tar.gz
ln -s mysql-5.7*-x86_64 mysql5.7
chown -R mysql:mysql $base
chown -R mysql:mysql $data
chmod -R 755 $data
#cd /usr/local
#ln -s $base/mysql5.7 /usr/local/mysql
rm -rf /etc/my.cnf
M="M"
cnf="/etc/my.cnf"
cat >>$cnf << END
[client]
port = $port
socket = $data/$port/mysql.sock
[mysql]
no-auto-rehash
prompt=(\\u@\\h) [\\d]>\\_
[mysqld]
# basic settings #
server_id = $ser_id
user = mysql
port = $port
basedir = $base/mysql5.7
datadir = $data/$port/data
socket = $data/$port/mysql.sock
pid-file = $data/$port/mysql.pid
log_error = $data/$port/log/error.log
sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER"
autocommit = 1
character_set_server=$char
transaction_isolation = READ-COMMITTED
explicit_defaults_for_timestamp = 1
max_allowed_packet = 16777216
event_scheduler = 1
tmpdir = $data/$port/tmp
log_timestamps=system
lower_case_table_names = 1
# connection #
interactive_timeout = 43200
wait_timeout = 43200
lock_wait_timeout = 43200
skip_name_resolve = 1
max_connections = 2000
max_connect_errors = 100000
# table cache performance settings #
table_open_cache = 4096
table_definition_cache = 4096
table_open_cache_instances = 64
# session memory settings #
read_buffer_size = 16M
read_rnd_buffer_size = 32M
sort_buffer_size = 32M
tmp_table_size = 64M
join_buffer_size = 128M
thread_cache_size = 64
# log settings #
slow_query_log = 1
slow_query_log_file = $data/$port/log/slow.log
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_throttle_queries_not_using_indexes = 10
expire_logs_days = 7
long_query_time = 2
min_examined_row_limit = 100
binlog-rows-query-log-events = 1
log-bin-trust-function-creators = 1
max_binlog_size = 512M
# InnoDB settings #
innodb_page_size = 16384
innodb_data_file_path = ibdata1:1G:autoextend
innodb_buffer_pool_size = $innodb$M
innodb_buffer_pool_instances = 16
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_lru_scan_depth = 4096
innodb_lock_wait_timeout = 50
innodb_io_capacity = 10000
innodb_io_capacity_max = 20000
innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_undo_logs = 128
innodb_undo_tablespaces = 3
innodb_flush_neighbors = 0
innodb_log_buffer_size = 16777216
innodb_log_file_size = 1048576000
innodb_log_files_in_group = 3
innodb_purge_threads = 4
innodb_large_prefix = 1
innodb_thread_concurrency = 64
innodb_print_all_deadlocks = 1
innodb_strict_mode = 1
innodb_sort_buffer_size = 67108864
innodb_write_io_threads = 16
innodb_read_io_threads = 16
innodb_file_per_table = 1
innodb_stats_persistent_sample_pages = 64
innodb_autoinc_lock_mode = 2
innodb_online_alter_log_max_size = 1G
innodb_open_files = 4096
innodb_flush_log_at_trx_commit = 1
# Myisam settings #
myisam_max_sort_file_size=512M
myisam_sort_buffer_size =8M
# replication settings #
#read_only = 1
skip_slave_start = 1
slave_parallel_workers = 4
slave_parallel_type = 'LOGICAL_CLOCK'
slave_preserve_commit_order = on
master_info_repository = table
relay_log_info_repository = table
sync_binlog = 1
gtid_mode = on
enforce_gtid_consistency = 1
log-slave-updates = 1
log_bin = $data/$port/binlog/mysql-bin
log_bin_index = $data/$port/binlog/binlog.index
binlog_format = row
binlog_row_image = minimal
binlog_rows_query_log_events = 1
#relay_log_index = $data/$port/binlog/relaylog.index
#relay_log = $data/$port/binlog/relay.log
#relay_log_recovery = 1
#slave_skip_errors = ddl_exist_errors
#slave-rows-search-algorithms = 'INDEX_SCAN,HASH_SCAN'
# semi sync replication settings #
#plugin_load = "validate_password.so;rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave.so'
#rpl_semi_sync_master_enabled = 1
#rpl_semi_sync_master_timeout = 3000
#rpl_semi_sync_slave_enabled= 1
# password plugin #
#validate_password_policy = strong
#validate-password = force_plus_permanent
END
chown mysql:mysql /etc/my.cnf
$base/mysql5.7/bin/mysqld --initialize --user=mysql
cd $base/mysql5.7/support-files/
cp mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on
service mysqld start
pass=`cat $data/$port/log/error.log | grep "A temporary password is" | awk '{print $NF}'`
sed -i "/\[client\]/a\user=root" /etc/my.cnf
sed -i "/\user=/a\password='$pass'" /etc/my.cnf
cat >>/etc/profile <<EOF
export PATH=$base/mysql5.7/bin:\$PATH
EOF
source /etc/profile
mysql --connect-expired-password -e "set password='mysql';"
sed -i '/user=/d' /etc/my.cnf
sed -i '/password=/d' /etc/my.cnf
mysql -uroot -pmysql -e "update mysql.user set User='mysqladmin' where user='root' and host='localhost';">/dev/null 2>/dev/null
mysql -uroot -pmysql -e "flush privileges;">/dev/null 2>/dev/null
mysql -umysqladmin -pmysql -e "create user @'%' identified by '';">/dev/null 2>/dev/null
mysql -umysqladmin -pmysql -e "grant process,replication client on *.* to @'%';">/dev/null 2>/dev/null
mysql -umysqladmin -pmysql -e "grant select on sys.* to @'%';">/dev/null 2>/dev/null
mysql -umysqladmin -pmysql -e "grant select on performance_schema.* to @'%';">/dev/null 2>/dev/null
mysql -umysqladmin -pmysql -e "create user tivoli@'%' identified by 'tivoli';">/dev/null 2>/dev/null
mysql -umysqladmin -pmysql -e "grant process,replication client on *.* to tivoli@'%';">/dev/null 2>/dev/null
mysql -umysqladmin -pmysql -e "grant select on sys.* to tivoli@'%';">/dev/null 2>/dev/null
mysql -umysqladmin -pmysql -e "grant select on performance_schema.* to tivoli@'%';">/dev/null 2>/dev/null
mysql -umysqladmin -pmysql -e "create user sjwh@'%' identified by 'sjwh';">/dev/null 2>/dev/null
mysql -umysqladmin -pmysql -e "grant SELECT, UPDATE, INSERT, DELETE, CREATE, DROP, RELOAD, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES,CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE on *.* to sjwh@'%';">/dev/null 2>/dev/null
sed -i '$d' /etc/profile
source /etc/profile
sed -i "/\[client\]/a\user=" /etc/my.cnf
sed -i "/\user=/a\password=" /etc/my.cnf
suce=`ps -ef | grep mysqld|wc -l`
if [ $suce -gt 2 ] ; then
echo "*******`date`*******"
echo "**********Install Sucessful!**********"
echo "******* MySQL User: mysqladmin ****"
echo "******* User Password: mysql ******"
echo "**************************************"
else
echo "*******`date`*******"
echo "***Install Failed,Please Check!***"
echo "**********************************"
fi
rm -rf /var/lock/subsys/mysql
break
;;
exit|EXIT)
exit
break
;;
*)
echo -n "please press y to continue,n to quit (Y/N):"
read cho
echo ""
;;
esac
done
break
;;
2)
################Default Quick Install################
##Define variables
read -p "Please Input MySQL Port (Default 3306): " port
port=${port:=3306}
read -p "Please Input MySQL BaseDir (Default /mysql/mysoft): " base
base=${base:='/mysql/mysoft'}
read -p "Please Input MySQL DataDir (Default /mysql/mydata): " data
data=${data:='/mysql/mydata'}
read -p "Please Input MySQL Server_Id (Default $id): " ser_id
ser_id=${ser_id:=$id}
read -p "Please Input MySQL Default Character (Default utf8): " char
char=${char:='utf8'}
read -p "Please Input MySQL Innodb_Buffer_size (Default $innobufsiz M): " innodb
innodb=${innodb:=$innobufsiz}
azlj=`pwd`
##create user
usero=`id mysql|awk '{print $1}'`
if [ -z "$usero" ];then
/usr/sbin/groupadd -g 600 mysql
/usr/sbin/useradd -u 600 -g mysql mysql
echo mysql | passwd mysql --stdin 1>/dev/null
echo ""
id mysql
echo ""
else
echo ""
id mysql
echo ""
echo -n "Do you want to use users (mysql) ("no" delet user and rebuild)[y|n] (Default y): "
read cho
cho=${cho:='y'}
echo ""
while true
do
case $cho in
N|NO|n|no)
/usr/sbin/userdel -r mysql 2>/dev/null
/usr/sbin/groupdel mysql 2>/dev/null
/usr/sbin/groupadd -g 600 mysql
/usr/sbin/useradd -u 600 -g mysql mysql
echo mysql | passwd mysql --stdin 1>/dev/null
id mysql
echo ""
break
;;
Y|YES|y|yes)
id mysql
echo mysql | passwd mysql --stdin 1>/dev/null
echo ""
break
;;
exit|EXIT)
exit
break
;;
*)
echo -n "Do you want to use users (mysql) ("no" delet user and rebuild)[y|n] (Default y): "
read cho
cho=${cho:='y'}
echo ""
;;
esac
done
fi
####################os check####################
echo "Check $base and $data"
mysql=`df -hm| grep -w $base | awk '{print $(NF-2)}'`
if [ ! -n "$mysql" ];then
echo "$base not have lv"
if [ ! -d "$base" ];then
echo "$base dose not exist;"
echo -n "please press y to create $base,n to quit (Y/N) (Default Y): "
read cho
cho=${cho:='y'}
echo ""
while true
do
case $cho in
N|NO|n|no)
echo "Please create $base !!!"
echo ""
exit
;;
Y|YES|y|yes)
mkdir -p $base
break
;;
esac
done
fi
else
if [ "$mysql" -lt 29000 ];then
echo '$base lv must >=30G'
fi
fi
mydata=`df -hm| grep -w $data | awk '{print $(NF-2)}'`
if [ ! -n "$mydata" ];then
echo "$data not have lv"
if [ ! -d "$data" ];then
echo "$data dose not exist;"
echo -n "please press y to create $data,n to quit (Y/N) (Default Y): "
read cho
cho=${cho:='y'}
echo ""
while true
do
case $cho in
N|NO|n|no)
echo "Please create $data !!!"
echo ""
exit
;;
Y|YES|y|yes)
mkdir -p $data
break
;;
esac
done
fi
else
if [ "$mydata" -lt 99000 ];then
echo '$data lv must >=100G'
fi
fi
echo " "
##osversion
os=`lsb_release -a|grep Description`
v_version=`echo ${os#*:}`
##check old mysql
echo "Check Old Mysql"
rpm=`rpm -qa | grep mysql`
if [ -z "$rpm" ];then
echo "check old mysql success!"
else
rpm -e $rpm --nodeps
echo "check old mysql: $rpm delete success!"
fi
echo " "
##print message
echo "|--------------------------------------------------------------------|"
echo " Os Version: $v_version "
echo " MemTotal: $mem M "
echo " BaseDir: $base "
echo " DataDir: $data "
echo " Port : $port "
echo " Server Id: $ser_id "
echo " Defalut Character: $char "
echo " Innodb_buffer_pool_size: $innodb M "
echo " Host Ipaddr: $rehost "
echo "|--------------------------------------------------------------------|"
echo " "
echo -n "please press y to continue,n to quit (Y/N) (Default Y): "
read cho
cho=${cho:='y'}
echo ""
while true
do
case $cho in
N|NO|n|no)
echo "Thanks!"
echo ""
break
;;
Y|YES|y|yes)
##new directory
mkdir -p $data/data
mkdir -p $data/log
mkdir -p $data/binlog
mkdir -p $data/tmp
##edit limits.conf
cat >>/etc/security/limits.conf << END
mysql hard nofile 65535
mysql soft nofile 65535
END
##edit .bash_profile
PROFILES="/home/mysql/.bash_profile"
for PROFILE in $PROFILES ; do
if [ -f "$PROFILE" ] ; then
if [ -z "$(grep "MySQL" $PROFILE)" ] ; then
cat >>$PROFILE << END
#MySQL
export MYSQL_HOME=$base
export PATH=\$MYSQL_HOME/mysql5.7/bin:\$PATH
END
echo "$PROFILE parameters : success"
else
echo "$PROFILE parameters : already existed"
fi
else
echo "$0: $PROFILE not found "
fi
done
##install software
cd $azlj
tar -xf mysql*5.7*tar* -C $base
cd $base
tar xf mysql-5.7*-x86_64.tar.gz
ln -s mysql-5.7*-x86_64 mysql5.7
chown -R mysql:mysql $base
chown -R mysql:mysql $data
chmod -R 755 $data
#cd /usr/local
#ln -s $base/mysql5.7 /usr/local/mysql
rm -rf /etc/my.cnf
M="M"
cnf="/etc/my.cnf"
cat >>$cnf << END
[client]
port = $port
socket = $data/mysql.sock
[mysql]
no-auto-rehash
prompt=(\\u@\\h) [\\d]>\\_
[mysqld]
# basic settings #
server_id = $ser_id
user = mysql
port = $port
basedir = $base/mysql5.7
datadir = $data/data
socket = $data/mysql.sock
pid-file = $data/mysql.pid
log_error = $data/log/error.log
sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER"
autocommit = 1
character_set_server=$char
transaction_isolation = READ-COMMITTED
explicit_defaults_for_timestamp = 1
max_allowed_packet = 16777216
event_scheduler = 1
tmpdir = $data/tmp
log_timestamps=system
lower_case_table_names = 1
# connection #
interactive_timeout = 43200
wait_timeout = 43200
lock_wait_timeout = 43200
skip_name_resolve = 1
max_connections = 2000
max_connect_errors = 100000
# table cache performance settings #
table_open_cache = 4096
table_definition_cache = 4096
table_open_cache_instances = 64
# session memory settings #
read_buffer_size = 16M
read_rnd_buffer_size = 32M
sort_buffer_size = 32M
tmp_table_size = 64M
join_buffer_size = 128M
thread_cache_size = 64
# log settings #
slow_query_log = 1
slow_query_log_file = $data/log/slow.log
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_throttle_queries_not_using_indexes = 10
expire_logs_days = 7
long_query_time = 2
min_examined_row_limit = 100
binlog-rows-query-log-events = 1
log-bin-trust-function-creators = 1
max_binlog_size = 512M
# InnoDB settings #
innodb_page_size = 16384
innodb_data_file_path = ibdata1:1G:autoextend
innodb_buffer_pool_size = $innodb$M
innodb_buffer_pool_instances = 16
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_lru_scan_depth = 4096
innodb_lock_wait_timeout = 50
innodb_io_capacity = 10000
innodb_io_capacity_max = 20000
innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_undo_logs = 128
innodb_undo_tablespaces = 3
innodb_flush_neighbors = 0
innodb_log_buffer_size = 16777216
innodb_log_file_size = 1048576000
innodb_log_files_in_group = 3
innodb_purge_threads = 4
innodb_large_prefix = 1
innodb_thread_concurrency = 64
innodb_print_all_deadlocks = 1
innodb_strict_mode = 1
innodb_sort_buffer_size = 67108864
innodb_write_io_threads = 16
innodb_read_io_threads = 16
innodb_file_per_table = 1
innodb_stats_persistent_sample_pages = 64
innodb_autoinc_lock_mode = 2
innodb_online_alter_log_max_size = 1G
innodb_open_files = 4096
innodb_flush_log_at_trx_commit = 1
# Myisam settings #
myisam_max_sort_file_size=512M
myisam_sort_buffer_size =8M
# replication settings #
#read_only = 1
skip_slave_start = 1
slave_parallel_workers = 4
slave_parallel_type = 'LOGICAL_CLOCK'
slave_preserve_commit_order = on
master_info_repository = table
relay_log_info_repository = table
sync_binlog = 1
gtid_mode = on
enforce_gtid_consistency = 1
log-slave-updates = 1
log_bin = $data/binlog/mysql-bin
log_bin_index = $data/binlog/binlog.index
binlog_format = row
binlog_row_image = minimal
binlog_rows_query_log_events = 1
#relay_log_index = $data/binlog/relaylog.index
#relay_log = $data/binlog/relay.log
#relay_log_recovery = 1
#slave_skip_errors = ddl_exist_errors
#slave-rows-search-algorithms = 'INDEX_SCAN,HASH_SCAN'
# semi sync replication settings #
#plugin_load = "validate_password.so;rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave.so'
#rpl_semi_sync_master_enabled = 1
#rpl_semi_sync_master_timeout = 3000
#rpl_semi_sync_slave_enabled= 1
# password plugin #
#validate_password_policy = strong
#validate-password = force_plus_permanent
END
chown mysql:mysql /etc/my.cnf
$base/mysql5.7/bin/mysqld --initialize --user=mysql
cd $base/mysql5.7/support-files/
cp mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on
service mysqld start
pass=`cat $data/log/error.log | grep "A temporary password is" | awk '{print $NF}'`
sed -i "/\[client\]/a\user=root" /etc/my.cnf
sed -i "/\user=/a\password='$pass'" /etc/my.cnf
cat >>/etc/profile <<EOF
export PATH=$base/mysql5.7/bin:\$PATH
EOF
source /etc/profile
mysql --connect-expired-password -e "set password='root';"
sed -i '/user=/d' /etc/my.cnf
sed -i '/password=/d' /etc/my.cnf
sed -i '$d' /etc/profile
source /etc/profile
suce=`ps -ef | grep mysqld|wc -l`
if [ $suce -gt 2 ] ; then
echo "*******`date`*******"
echo "*******Install Sucessful!*******"
echo "******* MySQL User: root *******"
echo "***** User Password : root *****"
echo "********************************"
else
echo "*******`date`*******"
echo "***Install Failed,Please Check!***"
echo "**********************************"
fi
rm -rf /var/lock/subsys/mysql
break
;;
exit|EXIT)
exit
break
;;
*)
echo -n "please press y to continue,n to quit (Y/N):"
read cho
echo ""
;;
esac
done
break
;;
3)
################Cancel Install################
break
;;
*)
read -p "please select [1-3] to continue :" which
;;
esac
done
fi