-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_mysql.sh
executable file
·102 lines (84 loc) · 2.79 KB
/
install_mysql.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
#!/bin/bash
#filename: install_mysql.sh
#Version: v1.0.0
#Author: LiLe
#Date: 20181124
#Contact: [email protected]
#Description: 以指定tar.gz包的方式安装Mysql,这里的版本是mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz;如果是自己下载不一样的版本,那么在main方法里注释掉down这一步,并且修改mysql_filename,改为你将安装的安装包名称;这里安装完成后如果使用mysql客户端命令使用不了,那么手动在命令行source /etc/profile一下。
#Usage: sudo sh install_mysql.sh
down(){
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
}
install_mysql(){
sudo yum -y install libaio*
install_dir=`echo ${mysql_install_dir%/*}`
dir_name=`echo ${mysql_install_dir##*/} `
if [ ! -d $install_dir ] ;then
sudo mkdir -p $install_dir
fi
tar -zxvf $mysql_filename -C $install_dir
static=`echo $mysql_filename |awk -F"-" '{print $2}'`
tar_filename=`ls $install_dir|grep $static`
sudo mv $install_dir/$tar_filename $install_dir/$dir_name
}
init_mysql(){
sudo useradd mysql
if [ ! -d $mysql_data ] ;then
sudo mkdir -p $mysql_data
fi
sudo chown -R mysql.mysql $mysql_data
sudo chmod -R 777 $mysql_data
sudo $mysql_install_dir/bin/mysqld --initialize --user=mysql --basedir=$mysql_install_dir --datadir=$mysql_data
}
config_mysql(){
if [ -f $config_file ] ;then
sudo cp $config_file $config_file\.bak
sudo rm $config_file
fi
sudo cp $mysql_install_dir/support-files/mysql.server /etc/init.d/mysql
sed -i "s!^basedir=!basedir=$mysql_install_dir!g" /etc/init.d/mysql
sed -i "s!^datadir=!datadir=$mysql_data!g" /etc/init.d/mysql
chmod +x /etc/init.d/mysql
echo "export PATH=\$PATH:$mysql_install_dir:$mysql_install_dir/bin" >> /etc/profile
source /etc/profile
cat <<EOF > $config_file
[mysqld]
datadir = ${mysql_data}
port = 3306
server_id = 1
socket = ${mysql_data}/mysql.sock
log-error = ${mysql_data}/mysql.error
pid-file = ${mysql_data}/mysql.pid
character_set_server = utf8
collation-server = utf8_general_ci
lower_case_table_names = 1
max_allowed_packet = 100M
max_connections = 1000
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
log-bin=master-bin
[client]
default-character-set=utf8
socket = ${mysql_data}/mysql.sock
[mysql]
default-character-set=utf8
EOF
}
start_mysql(){
sudo chmod 777 $mysql_data/ibdata1
sudo rm $mysql_data/ib_logfile0
sudo rm $mysql_data/ib_logfile1
sudo systemctl daemon-reload
sudo systemctl start mysql
}
main(){
mysql_install_dir=/usr/local/mysql
mysql_filename=mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
mysql_data=/data/mysql
config_file=/etc/my.cnf
down
install_mysql
init_mysql
config_mysql
start_mysql
}
main