forked from Neeky/mysqltools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstallmysql.sh
33 lines (23 loc) · 940 Bytes
/
installmysql.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
#!/bin/bash
#config information ...
username=mysql
datadir=/data/3306
mysqlversion=mysql-5.7.18-linux-glibc2.5-x86_64
installpacket=mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
#第一步:增加mysql用户
useradd mysql
#第二步:创建数据目录
mkdir -p $datadir && chown -R $username:$username /data
#第三步:解压安装介质
tar -xzvf $installpacket -C /usr/local/
ln -s /usr/local/$mysqlversion /usr/local/mysql
#第四步:初始化数据库
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --user=$username \
--basedir=/usr/local/mysql/ --datadir=$datadir --initialize-insecure
#第五步:配置服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig mysqld on
service mysqld start
#第六步:用户管理
/usr/local/mysql/bin/mysql -e'create user appuser@"%" identified by "Pass@123";'
/usr/local/mysql/bin/mysql -e'alter user root@"localhost" identified by "Root@123";'