blob: 14034726c986574d2c5bbbe6f4f4f263f00b5493 [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
Ales Komarek04991c02016-10-05 10:02:59 +0200173
174MySQL client role
175-----------------
176
177Database management on remote MySQL server
178
179.. code-block:: yaml
180
181 mysql:
182 client:
183 enabled: true
184 server:
185 server01:
186 admin:
187 host: database.host
188 port: 3306
189 user: root
190 password: password
191 encoding: utf8
192 database:
193 database01:
194 encoding: utf8
195 users:
196 - name: username
197 password: 'password'
198 host: 'localhost'
199 rights: 'all privileges'
200
201User management on remote MySQL server
202
203.. code-block:: yaml
204
205 mysql:
206 client:
207 enabled: true
208 server:
209 server01:
210 admin:
211 host: database.host
212 port: 3306
213 user: root
214 password: password
215 encoding: utf8
216 users:
217 - name: user01
218 host: "*"
219 password: 'sdgdsgdsgd'
220 - name: user02
221 host: "localhost"
222
223
Filip Pytloun5b3c12e2015-10-06 16:28:32 +0200224Usage
225=====
226
227MySQL Galera check sripts
228
229.. code-block:: bash
230
231 mysql> SHOW STATUS LIKE 'wsrep%';
232
233 mysql> SHOW STATUS LIKE 'wsrep_cluster_size' ;"
234
235Galera monitoring command, performed from extra server
236
237.. code-block:: bash
238
239 garbd -a gcomm://ipaddrofone:4567 -g my_wsrep_cluster -l /tmp/1.out -d
240
2411. salt-call state.sls mysql
2422. Comment everything starting wsrep* (wsrep_provider, wsrep_cluster, wsrep_sst)
2433. service mysql start
2444. run on each node mysql_secure_install and filling root password.
245
246.. code-block:: bash
247
248 Enter current password for root (enter for none):
249 OK, successfully used password, moving on...
250
251 Setting the root password ensures that nobody can log into the MySQL
252 root user without the proper authorisation.
253
254 Set root password? [Y/n] y
255 New password:
256 Re-enter new password:
257 Password updated successfully!
258 Reloading privilege tables..
259 ... Success!
260
261 By default, a MySQL installation has an anonymous user, allowing anyone
262 to log into MySQL without having to have a user account created for
263 them. This is intended only for testing, and to make the installation
264 go a bit smoother. You should remove them before moving into a
265 production environment.
266
267 Remove anonymous users? [Y/n] y
268 ... Success!
269
270 Normally, root should only be allowed to connect from 'localhost'. This
271 ensures that someone cannot guess at the root password from the network.
272
273 Disallow root login remotely? [Y/n] n
274 ... skipping.
275
276 By default, MySQL comes with a database named 'test' that anyone can
277 access. This is also intended only for testing, and should be removed
278 before moving into a production environment.
279
280 Remove test database and access to it? [Y/n] y
281 - Dropping test database...
282 ... Success!
283 - Removing privileges on test database...
284 ... Success!
285
286 Reloading the privilege tables will ensure that all changes made so far
287 will take effect immediately.
288
289 Reload privilege tables now? [Y/n] y
290 ... Success!
291
292 Cleaning up...
293
2945. service mysql stop
2956. uncomment all wsrep* lines except first server, where leave only in my.cnf wsrep_cluster_address='gcomm://';
2967. start first node
2978. Start third node which is connected to first one
2989. Start second node which is connected to third one
29910. After starting cluster, it must be change cluster address at first starting node without restart database and change config my.cnf.
300
301.. code-block:: bash
302
303 mysql> SET GLOBAL wsrep_cluster_address='gcomm://10.0.0.2';
304
305Read more
306=========
307
308* http://dev.mysql.com/doc/
309* http://www.slideshare.net/osscube/mysql-performance-tuning-top-10-tips
310
311Galera replication
312------------------
313
314* https://github.com/CaptTofu/ansible-galera
315* http://www.sebastien-han.fr/blog/2012/04/15/active-passive-failover-cluster-on-a-mysql-galera-cluster-with-haproxy-lsb-agent/
316* http://opentodo.net/2012/12/mysql-multi-master-replication-with-galera/
317* http://www.codership.com/wiki/doku.php
318* Best one: - http://www.sebastien-han.fr/blog/2012/04/01/mysql-multi-master-replication-with-galera/
319
320Mysql Backup
321------------
322
323* http://sourceforge.net/projects/automysqlbackup/
324* https://labs.riseup.net/code/projects/backupninja/wiki
325* http://wiki.zmanda.com/index.php/Mysql-zrm