-
Notifications
You must be signed in to change notification settings - Fork 18
/
mariadb.sh
47 lines (40 loc) · 1.17 KB
/
mariadb.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
#!/bin/bash
echo ">>> Installing MariaDB <<<"
# default version
MARIADB_VERSION='10.1'
# Install MariaDB
sudo apt-get install -y php-mysql mariadb-server mariadb-client
sudo mysql_secure_installation
# Make Maria connectable from outside world without SSH tunnel
echo ''
read -p "Enable remote access this MariaDB [y/n] " remotemysql
if [[ $remotemysql =~ ^[Yy]$ ]]
then
if [ -z $1 ]
then
echo ''
read -sp "Confirm MySQL root password : " pswd
else
pswd=$1
fi
if [ -z $pswd ]
then
echo "Password is required!"
exit 1
else
# enable remote access
sed -i "s/bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/mariadb.conf.d/50-server.cnf
# adding grant privileges to mysql root user from everywhere
MYSQL='mysql'
Q1="GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '$pswd' WITH GRANT OPTION;"
Q2="FLUSH PRIVILEGES;"
Q3="UPDATE mysql.user SET plugin='' WHERE user='root';"
Q4="FLUSH PRIVILEGES;"
SQL="${Q1}${Q2}${Q3}${Q4}"
$MYSQL -uroot -p$pswd -e "$SQL"
# Restart MySQL
sudo service mysql restart
fi
fi
echo ">>> Finished Installing MariaDB"
sleep 2