replication.inc.php
4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Replication helpers
*
* @package PhpMyAdmin
*/
if (! defined('PHPMYADMIN')) {
exit;
}
use PhpMyAdmin\Replication;
/**
* get master replication from server
*/
$server_master_replication = $GLOBALS['dbi']->fetchResult('SHOW MASTER STATUS');
/**
* set selected master server
*/
if (! empty($_POST['master_connection'])) {
/**
* check for multi-master replication functionality
*/
$server_slave_multi_replication = $GLOBALS['dbi']->fetchResult(
'SHOW ALL SLAVES STATUS'
);
if ($server_slave_multi_replication) {
$GLOBALS['dbi']->query(
"SET @@default_master_connection = '"
. $GLOBALS['dbi']->escapeString(
$_POST['master_connection']
) . "'"
);
$GLOBALS['url_params']['master_connection'] = $_POST['master_connection'];
}
}
/**
* get slave replication from server
*/
$server_slave_replication = $GLOBALS['dbi']->fetchResult('SHOW SLAVE STATUS');
/**
* replication types
*/
$replication_types = array('master', 'slave');
/**
* define variables for master status
*/
$master_variables = array(
'File',
'Position',
'Binlog_Do_DB',
'Binlog_Ignore_DB',
);
/**
* Define variables for slave status
*/
$slave_variables = array(
'Slave_IO_State',
'Master_Host',
'Master_User',
'Master_Port',
'Connect_Retry',
'Master_Log_File',
'Read_Master_Log_Pos',
'Relay_Log_File',
'Relay_Log_Pos',
'Relay_Master_Log_File',
'Slave_IO_Running',
'Slave_SQL_Running',
'Replicate_Do_DB',
'Replicate_Ignore_DB',
'Replicate_Do_Table',
'Replicate_Ignore_Table',
'Replicate_Wild_Do_Table',
'Replicate_Wild_Ignore_Table',
'Last_Errno',
'Last_Error',
'Skip_Counter',
'Exec_Master_Log_Pos',
'Relay_Log_Space',
'Until_Condition',
'Until_Log_File',
'Until_Log_Pos',
'Master_SSL_Allowed',
'Master_SSL_CA_File',
'Master_SSL_CA_Path',
'Master_SSL_Cert',
'Master_SSL_Cipher',
'Master_SSL_Key',
'Seconds_Behind_Master',
);
/**
* define important variables, which need to be watched for
* correct running of replication in slave mode
*
* @usedby PhpMyAdmin\ReplicationGui::getHtmlForReplicationStatusTable()
*/
// TODO change to regexp or something, to allow for negative match.
// To e.g. highlight 'Last_Error'
//
$slave_variables_alerts = array(
'Slave_IO_Running' => 'No',
'Slave_SQL_Running' => 'No',
);
$slave_variables_oks = array(
'Slave_IO_Running' => 'Yes',
'Slave_SQL_Running' => 'Yes',
);
// check which replication is available and
// set $server_{master/slave}_status and assign values
// replication info is more easily passed to functions
$GLOBALS['replication_info'] = array();
foreach ($replication_types as $type) {
if (count(${"server_{$type}_replication"}) > 0) {
$GLOBALS['replication_info'][$type]['status'] = true;
} else {
$GLOBALS['replication_info'][$type]['status'] = false;
}
if ($GLOBALS['replication_info'][$type]['status']) {
if ($type == "master") {
Replication::fillInfo(
$type, 'Do_DB', $server_master_replication[0],
'Binlog_Do_DB'
);
Replication::fillInfo(
$type, 'Ignore_DB', $server_master_replication[0],
'Binlog_Ignore_DB'
);
} elseif ($type == "slave") {
Replication::fillInfo(
$type, 'Do_DB', $server_slave_replication[0],
'Replicate_Do_DB'
);
Replication::fillInfo(
$type, 'Ignore_DB', $server_slave_replication[0],
'Replicate_Ignore_DB'
);
Replication::fillInfo(
$type, 'Do_Table', $server_slave_replication[0],
'Replicate_Do_Table'
);
Replication::fillInfo(
$type, 'Ignore_Table', $server_slave_replication[0],
'Replicate_Ignore_Table'
);
Replication::fillInfo(
$type, 'Wild_Do_Table', $server_slave_replication[0],
'Replicate_Wild_Do_Table'
);
Replication::fillInfo(
$type, 'Wild_Ignore_Table', $server_slave_replication[0],
'Replicate_Wild_Ignore_Table'
);
}
}
}