MediaWiki/Sql: Difference between revisions
syntax / typo |
m Text replacement - "<(\/?)source" to "<$1syntaxhighlight" Tags: Mobile edit Mobile web edit |
||
| Line 14: | Line 14: | ||
==Debugging with the General Query Log== | ==Debugging with the General Query Log== | ||
In the mysql console, you can use a global variable to turn logging on | In the mysql console, you can use a global variable to turn logging on | ||
< | <syntaxhighlight lang="mysql"> | ||
SET global general_log = 1; | SET global general_log = 1; | ||
</ | </syntaxhighlight> | ||
And specify the log file (The MySQL user must have write permission to this file.) | And specify the log file (The MySQL user must have write permission to this file.) | ||
< | <syntaxhighlight lang="mysql"> | ||
SET global general_log_file = '/var/log/mariadb/mariadb.log'; | SET global general_log_file = '/var/log/mariadb/mariadb.log'; | ||
</ | </syntaxhighlight> | ||
Then you can do some action that you want to examine the queries for, and '''TURN OFF''' the general query log immediately. A busy server will fill up all disk space with a huge log file if you don't turn it off. | Then you can do some action that you want to examine the queries for, and '''TURN OFF''' the general query log immediately. A busy server will fill up all disk space with a huge log file if you don't turn it off. | ||
< | <syntaxhighlight lang="mysql"> | ||
SET global general_log = 0; | SET global general_log = 0; | ||
</ | </syntaxhighlight> | ||
==Query Examples== | ==Query Examples== | ||
| Line 30: | Line 30: | ||
Some database queries that you might want to use and bookmark in your database administration tool such as [https://dev.mysql.com/downloads/workbench/ MySQL Workbench] or SQLyog http://www.webyog.com/en/index.php | Some database queries that you might want to use and bookmark in your database administration tool such as [https://dev.mysql.com/downloads/workbench/ MySQL Workbench] or SQLyog http://www.webyog.com/en/index.php | ||
< | <syntaxhighlight lang="mysql"> | ||
-- what database schema do you want to use? | -- what database schema do you want to use? | ||
use wiki_demo; | use wiki_demo; | ||
| Line 42: | Line 42: | ||
FROM information_schema.columns AS cols | FROM information_schema.columns AS cols | ||
WHERE table_schema = 'wiki_demo'; | WHERE table_schema = 'wiki_demo'; | ||
</ | </syntaxhighlight> | ||
Here is a query that will show you the pages in your wiki that contain a particular string. In this example, I wanted to find all pages that were using the 'Icon' extension parser extension magic word '#icon'. | Here is a query that will show you the pages in your wiki that contain a particular string. In this example, I wanted to find all pages that were using the 'Icon' extension parser extension magic word '#icon'. | ||
< | <syntaxhighlight lang="mysql"> | ||
SELECT DISTINCT | SELECT DISTINCT | ||
page_title | page_title | ||
| Line 64: | Line 64: | ||
old_text REGEXP('#icon') # regex is easier to deal with | old_text REGEXP('#icon') # regex is easier to deal with | ||
) | ) | ||
</ | </syntaxhighlight> | ||
A more complex query that summarizes some information about an article | A more complex query that summarizes some information about an article | ||
(You supply the article title) | (You supply the article title) | ||
< | <syntaxhighlight lang="mysql"> | ||
SELECT | SELECT | ||
p.page_id 'id', | p.page_id 'id', | ||
| Line 90: | Line 90: | ||
WHERE | WHERE | ||
p.page_title = 'Main_Page' | p.page_title = 'Main_Page' | ||
</ | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||