mariadb/service-install.sh

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