mariadb/service-install.sh

raw link view readme
1 cat > /etc/yum.repos.d/mariadb.repo << EOF
2 [mariadb]
3 name = MariaDB
4 baseurl = http://yum.mariadb.org/10.1/centos7-amd64
5 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
6 gpgcheck=1
7 EOF
8
9 yum install MariaDB-server -y
10
11 sed -i.original "s/\[mysqld\]/[mysqld]\nport=3307/" /etc/my.cnf.d/server.cnf
12
13 systemctl start mariadb
14 systemctl enable mariadb
15
16 mysql_secure_installation <<\EOF
17
18 y
19 secret
20 secret
21 y
22 y
23 y
24 y
25 EOF
26
27 yum install firewalld -y
28 sed "s/\"80\"/\"3307\"/;s/WWW (HTTP)/MariaDB (custom port)/;/.*/d" /usr/lib/firewalld/services/http.xml > /etc/firewalld/services/mariadb-custom.xml
29 systemctl start firewalld
30 systemctl enable firewalld
31 firewall-cmd --permanent --zone=public --add-interface=eth0
32 firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.18.0.0/24" service name="mariadb-custom" accept' --zone=public
33 firewall-cmd --reload
34
35 mysql -psecret <<\EOF
36 CREATE DATABASE elephant01;
37
38 USE elephant01;
39 CREATE TABLE table01 (
40 id INT AUTO_INCREMENT,
41 name VARCHAR(20),
42 PRIMARY KEY (id)
43 );
44
45 CREATE USER dbetz@'%' IDENTIFIED BY 'mypassword';
46 GRANT ALL PRIVILEGES ON *.* TO dbetz@'%';
47 CREATE USER dbetz@'localhost' IDENTIFIED BY 'mypassword';
48 GRANT ALL PRIVILEGES ON *.* TO dbetz@'localhost';
49 FLUSH PRIVILEGES;
50
51 CREATE USER user01@'%' IDENTIFIED BY 'mypassword';
52 GRANT SELECT, INSERT, UPDATE, DELETE ON elephant01.* TO user01@'%';
53 CREATE USER user01@'localhost' IDENTIFIED BY 'mypassword';
54 GRANT SELECT, INSERT, UPDATE, DELETE ON elephant01.* TO user01@'localhost';
55 FLUSH PRIVILEGES;
56 EOF
57
58 mysql -psecret --execute 'CREATE DATABASE Library;'
59 mysql -psecret <<\EOF
60 CREATE USER librarian01@'%' IDENTIFIED BY 'mypassword';
61 GRANT SELECT, INSERT, UPDATE, DELETE ON Library.* TO librarian01@'%';
62 CREATE USER librarian01@'localhost' IDENTIFIED BY 'mypassword';
63 GRANT SELECT, INSERT, UPDATE, DELETE ON Library.* TO librarian01@'localhost';
64 EOF
65
66 wget https://linux.azure.david.betz.space/raw/mariadb/mariadb-library.sql -O /var/tmp/mariadb-library.sql
67 mysql -psecret Library < /var/tmp/mariadb-library.sql
68