blob: 1c5df0f507c1e6bd454d076b024ef3f3a31baad8 [file] [log] [blame]
Filip Pytloun5b3c12e2015-10-06 16:28:32 +02001
2=====
3MySQL
4=====
5
6MySQL is the world's second most widely used open-source relational database management system (RDBMS).
7
8Sample pillars
9==============
10
11Standalone servers
12------------------
13
14Standalone MySQL server
15
16.. code-block:: yaml
17
18 mysql:
19 server:
20 enabled: true
21 version: '5.5'
22 admin:
23 user: root
24 password: pass
25 bind:
26 address: '127.0.0.1'
27 port: 3306
28 database:
29 name:
30 encoding: 'utf8'
31 users:
32 - name: 'username'
33 password: 'password'
34 host: 'localhost'
35 rights: 'all privileges'
36
37MySQL replication master with SSL
38
39.. code-block:: yaml
40
41 mysql:
42 server:
43 enabled: true
44 version: 5.5
45 replication:
46 role: master
47 ssl:
48 enabled: true
49 authority: Org_CA
50 certificate: name_of_service
51 admin:
52 user: root
53 password: pass
54 bind:
55 address: '127.0.0.1'
56 port: 3306
57
58MySQL replication slave with SSL
59
60.. code-block:: yaml
61
62 mysql:
63 server:
64 enabled: true
65 version: '5.5'
66 replication:
67 role: slave
68 master: master.salt.id
69 ssl:
70 enabled: true
71 authority: Org_CA
72 certificate: name_of_service
73 client_certificate: name_of_client_cert
74 admin:
75 user: root
76 password: pass
77 bind:
78 address: '127.0.0.1'
79 port: 3306
80
81Tuned up MySQL server
82
83.. code-block:: yaml
84
85 mysql:
86 server:
87 enabled: true
88 version: '5.5'
89 admin:
90 user: root
91 password: pass
92 bind:
93 address: '127.0.0.1'
94 port: 3306
95 key_buffer: 250M
96 max_allowed_packet: 32M
97 max_connections: 1000
98 thread_stack: 512K
99 thread_cache_size: 64
100 query_cache_limit: 16M
101 query_cache_size: 96M
102 force_encoding: utf8
Jakub Pavlikda755f22016-09-02 12:06:53 +0200103 sql_mode: "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Filip Pytloun5b3c12e2015-10-06 16:28:32 +0200104 database:
105 name:
106 encoding: 'utf8'
107 users:
108 - name: 'username'
109 password: 'password'
110 host: 'localhost'
111 rights: 'all privileges'
112
113MySQL galera cluster
114--------------------
115
116MySQL Galera cluster is configured for ring connection between 3 nodes. Each node should have just one member.
117
118Galera initial server (master)
119
120.. code-block:: yaml
121
122 mysql:
123 cluster:
124 enabled: true
125 name: openstack
126 role:master
127 bind:
128 address: 192.168.0.1
129 members:
130 - host: 192.168.0.1
131 port: 4567
132 user:
133 name: wsrep_sst
134 password: password
135 server:
136 enabled: true
137 version: 5.5
138 admin:
139 user: root
140 password: pass
141 bind:
142 address: 192.168.0.1
143 database:
144 name:
145 encoding: 'utf8'
146 users:
147 - name: 'username'
148 password: 'password'
149 host: 'localhost'
150 rights: 'all privileges'
151
Jakub Pavlikf4396652016-07-11 15:06:33 +0200152Database management
153---------------------
154
155User, Database management on independent mysql server
156
157.. code-block:: yaml
158
159 mysql:
160 server:
161 admin:
162 user: root
163 password: pass
164 database:
165 name:
166 encoding: 'utf8'
167 users:
168 - name: 'username'
169 password: 'password'
170 host: 'localhost'
171 rights: 'all privileges'
172
Filip Pytloun5b3c12e2015-10-06 16:28:32 +0200173Usage
174=====
175
176MySQL Galera check sripts
177
178.. code-block:: bash
179
180 mysql> SHOW STATUS LIKE 'wsrep%';
181
182 mysql> SHOW STATUS LIKE 'wsrep_cluster_size' ;"
183
184Galera monitoring command, performed from extra server
185
186.. code-block:: bash
187
188 garbd -a gcomm://ipaddrofone:4567 -g my_wsrep_cluster -l /tmp/1.out -d
189
1901. salt-call state.sls mysql
1912. Comment everything starting wsrep* (wsrep_provider, wsrep_cluster, wsrep_sst)
1923. service mysql start
1934. run on each node mysql_secure_install and filling root password.
194
195.. code-block:: bash
196
197 Enter current password for root (enter for none):
198 OK, successfully used password, moving on...
199
200 Setting the root password ensures that nobody can log into the MySQL
201 root user without the proper authorisation.
202
203 Set root password? [Y/n] y
204 New password:
205 Re-enter new password:
206 Password updated successfully!
207 Reloading privilege tables..
208 ... Success!
209
210 By default, a MySQL installation has an anonymous user, allowing anyone
211 to log into MySQL without having to have a user account created for
212 them. This is intended only for testing, and to make the installation
213 go a bit smoother. You should remove them before moving into a
214 production environment.
215
216 Remove anonymous users? [Y/n] y
217 ... Success!
218
219 Normally, root should only be allowed to connect from 'localhost'. This
220 ensures that someone cannot guess at the root password from the network.
221
222 Disallow root login remotely? [Y/n] n
223 ... skipping.
224
225 By default, MySQL comes with a database named 'test' that anyone can
226 access. This is also intended only for testing, and should be removed
227 before moving into a production environment.
228
229 Remove test database and access to it? [Y/n] y
230 - Dropping test database...
231 ... Success!
232 - Removing privileges on test database...
233 ... Success!
234
235 Reloading the privilege tables will ensure that all changes made so far
236 will take effect immediately.
237
238 Reload privilege tables now? [Y/n] y
239 ... Success!
240
241 Cleaning up...
242
2435. service mysql stop
2446. uncomment all wsrep* lines except first server, where leave only in my.cnf wsrep_cluster_address='gcomm://';
2457. start first node
2468. Start third node which is connected to first one
2479. Start second node which is connected to third one
24810. After starting cluster, it must be change cluster address at first starting node without restart database and change config my.cnf.
249
250.. code-block:: bash
251
252 mysql> SET GLOBAL wsrep_cluster_address='gcomm://10.0.0.2';
253
254Read more
255=========
256
257* http://dev.mysql.com/doc/
258* http://www.slideshare.net/osscube/mysql-performance-tuning-top-10-tips
259
260Galera replication
261------------------
262
263* https://github.com/CaptTofu/ansible-galera
264* http://www.sebastien-han.fr/blog/2012/04/15/active-passive-failover-cluster-on-a-mysql-galera-cluster-with-haproxy-lsb-agent/
265* http://opentodo.net/2012/12/mysql-multi-master-replication-with-galera/
266* http://www.codership.com/wiki/doku.php
267* Best one: - http://www.sebastien-han.fr/blog/2012/04/01/mysql-multi-master-replication-with-galera/
268
269Mysql Backup
270------------
271
272* http://sourceforge.net/projects/automysqlbackup/
273* https://labs.riseup.net/code/projects/backupninja/wiki
274* http://wiki.zmanda.com/index.php/Mysql-zrm