blob: 38d241301f99fa5f074515808727bf7860b21a76 [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
103 database:
104 name:
105 encoding: 'utf8'
106 users:
107 - name: 'username'
108 password: 'password'
109 host: 'localhost'
110 rights: 'all privileges'
111
112MySQL galera cluster
113--------------------
114
115MySQL Galera cluster is configured for ring connection between 3 nodes. Each node should have just one member.
116
117Galera initial server (master)
118
119.. code-block:: yaml
120
121 mysql:
122 cluster:
123 enabled: true
124 name: openstack
125 role:master
126 bind:
127 address: 192.168.0.1
128 members:
129 - host: 192.168.0.1
130 port: 4567
131 user:
132 name: wsrep_sst
133 password: password
134 server:
135 enabled: true
136 version: 5.5
137 admin:
138 user: root
139 password: pass
140 bind:
141 address: 192.168.0.1
142 database:
143 name:
144 encoding: 'utf8'
145 users:
146 - name: 'username'
147 password: 'password'
148 host: 'localhost'
149 rights: 'all privileges'
150
Jakub Pavlikf4396652016-07-11 15:06:33 +0200151Database management
152---------------------
153
154User, Database management on independent mysql server
155
156.. code-block:: yaml
157
158 mysql:
159 server:
160 admin:
161 user: root
162 password: pass
163 database:
164 name:
165 encoding: 'utf8'
166 users:
167 - name: 'username'
168 password: 'password'
169 host: 'localhost'
170 rights: 'all privileges'
171
Filip Pytloun5b3c12e2015-10-06 16:28:32 +0200172Usage
173=====
174
175MySQL Galera check sripts
176
177.. code-block:: bash
178
179 mysql> SHOW STATUS LIKE 'wsrep%';
180
181 mysql> SHOW STATUS LIKE 'wsrep_cluster_size' ;"
182
183Galera monitoring command, performed from extra server
184
185.. code-block:: bash
186
187 garbd -a gcomm://ipaddrofone:4567 -g my_wsrep_cluster -l /tmp/1.out -d
188
1891. salt-call state.sls mysql
1902. Comment everything starting wsrep* (wsrep_provider, wsrep_cluster, wsrep_sst)
1913. service mysql start
1924. run on each node mysql_secure_install and filling root password.
193
194.. code-block:: bash
195
196 Enter current password for root (enter for none):
197 OK, successfully used password, moving on...
198
199 Setting the root password ensures that nobody can log into the MySQL
200 root user without the proper authorisation.
201
202 Set root password? [Y/n] y
203 New password:
204 Re-enter new password:
205 Password updated successfully!
206 Reloading privilege tables..
207 ... Success!
208
209 By default, a MySQL installation has an anonymous user, allowing anyone
210 to log into MySQL without having to have a user account created for
211 them. This is intended only for testing, and to make the installation
212 go a bit smoother. You should remove them before moving into a
213 production environment.
214
215 Remove anonymous users? [Y/n] y
216 ... Success!
217
218 Normally, root should only be allowed to connect from 'localhost'. This
219 ensures that someone cannot guess at the root password from the network.
220
221 Disallow root login remotely? [Y/n] n
222 ... skipping.
223
224 By default, MySQL comes with a database named 'test' that anyone can
225 access. This is also intended only for testing, and should be removed
226 before moving into a production environment.
227
228 Remove test database and access to it? [Y/n] y
229 - Dropping test database...
230 ... Success!
231 - Removing privileges on test database...
232 ... Success!
233
234 Reloading the privilege tables will ensure that all changes made so far
235 will take effect immediately.
236
237 Reload privilege tables now? [Y/n] y
238 ... Success!
239
240 Cleaning up...
241
2425. service mysql stop
2436. uncomment all wsrep* lines except first server, where leave only in my.cnf wsrep_cluster_address='gcomm://';
2447. start first node
2458. Start third node which is connected to first one
2469. Start second node which is connected to third one
24710. After starting cluster, it must be change cluster address at first starting node without restart database and change config my.cnf.
248
249.. code-block:: bash
250
251 mysql> SET GLOBAL wsrep_cluster_address='gcomm://10.0.0.2';
252
253Read more
254=========
255
256* http://dev.mysql.com/doc/
257* http://www.slideshare.net/osscube/mysql-performance-tuning-top-10-tips
258
259Galera replication
260------------------
261
262* https://github.com/CaptTofu/ansible-galera
263* http://www.sebastien-han.fr/blog/2012/04/15/active-passive-failover-cluster-on-a-mysql-galera-cluster-with-haproxy-lsb-agent/
264* http://opentodo.net/2012/12/mysql-multi-master-replication-with-galera/
265* http://www.codership.com/wiki/doku.php
266* Best one: - http://www.sebastien-han.fr/blog/2012/04/01/mysql-multi-master-replication-with-galera/
267
268Mysql Backup
269------------
270
271* http://sourceforge.net/projects/automysqlbackup/
272* https://labs.riseup.net/code/projects/backupninja/wiki
273* http://wiki.zmanda.com/index.php/Mysql-zrm