What table in the mediawiki database holds the page content? I want to access the mediawiki's database directly.
You can take a look at the database layout of MediaWiki. The page content is located in the table text (on PostgreSQL it seems to be pagecontent)
I recently had a mediawiki installation go so wrong I needed to retrieve page content directly from the database. Below is the MYSQL statement I was able to use to retrieve the page content with.
SELECT `old_text`
FROM `mw_text`
WHERE `old_id`
IN (
SELECT `rev_text_id`
FROM `mw_revision`
LEFT JOIN `mw_page` ON `page_latest` = `rev_id`
WHERE `page_title` LIKE (
'%title_of_the_page%'
)
)
Note: my table prefix is mw_ yours will probably be different
Used this relationship to recover pages:
page.page_latest=revision.rev_id -> revision.rev_text_id=text.old_id -> text.old_text
Ref: http://www.mediawiki.org/wiki/Manual:Page_table
I recently wanted to find articles containing URL, that the MediaWiki search
engine could not find for some reason. In MediaWiki 1.35 the rev_text_id
column has been deleted, so willcwf's
answer did not work for me.
Basing on information from the MediaWiki documentation, I was able to create a
SQL query that works with newer MediaWiki versions:
SELECT
(CASE
WHEN p.page_namespace = 0 THEN '(Main)'
WHEN p.page_namespace = 2 THEN 'User'
WHEN p.page_namespace = 4 THEN 'Project'
WHEN p.page_namespace = 6 THEN 'File'
WHEN p.page_namespace = 8 THEN 'MediaWiki'
WHEN p.page_namespace = 10 THEN 'Template'
WHEN p.page_namespace = 12 THEN 'Help'
WHEN p.page_namespace = 14 THEN 'Category'
ELSE p.page_namespace
END) as Namespace,
p.page_title AS Title,
t.old_text AS 'Text'
FROM
page p
JOIN slots s ON
s.slot_revision_id = p.page_latest
JOIN content c ON
c.content_id = s.slot_content_id
JOIN `text` t ON
t.old_id = REPLACE(c.content_address, 'tt:', '')
WHERE t.old_text LIKE '%needle%';
Related
I use Laravel 6 for one of my app. I am stuck in a performance problem for post page in my app.
The most popular page is post page in my app. Typically the post page has:
PostPage content,
Comments of post content and subComments (as tree) for all comment,
and comment liking, rating (Is the member liked this comment) again for all comment
E.g: if the page has +10 comments, the app will be, slowly and mysqld high.
An example for SQL Query in my code block:
SELECT `comments`.`id`, `comments`.`comment`, `comments`.`parent_id`, `comments`.`date`,
`comments`.`ratingN`, `comments`.`ratingP`, `rating`.`rate`, `users`.`photo`,
`users`.`photo2`, `users`.`username`, `users`.`gold_end`,
(CASE WHEN rating.id_user = 7 THEN 1 ELSE 0 END) as liked
FROM `comments`
inner join `users` on `comments`.`id_user` = `users`.`id`
left join `rating` on `rating`.`id_comment` = `comments`.`id`
where `parent_id` = 284162 and `status` = 1
group by `comments`.`date` order by `date` asc
I use (query) cache but again the first opening and after any update the post page works slowly because of comments side. Using joins.
I call the main comments and than, look that mainComments have any subComments,
The comments are liked by this member?
PHP 7.2, MySQL 5.7
What are your suggestions?
These composite indexes might help:
comments: INDEX(parent_id, status, date)
rating: INDEX(id_comment, id_user, rate)
users: I assume you have `PRIMARY KEY(Id)`?
I've recently migrated a shop from shared server to VPS. Copied all files to the new server and imported the database. Completed the initial set ups. Now the homepage of the site is loading, but all other pages showing database exception. It is showing a long query. Can someone suggest me something. My mysql connect timeout is 60 secs. The query is so long that posting here freezes the browser. I'm posting an exrept of that sql query. Can someone suggest me something over this ?
SELECT product_shop.id_product, MAX(product_attribute_shop.id_product_attribute) id_product_attribute
FROM `awfps_product` p
INNER JOIN awfps_product_shop product_shop
ON (product_shop.id_product = p.id_product AND product_shop.id_shop = 1)
LEFT JOIN `awfps_product_attribute` pa ON (product_shop.id_product = pa.id_product)
LEFT JOIN awfps_product_attribute_shop product_attribute_shop
ON (product_attribute_shop.id_product_attribute = pa.id_product_attribute AND product_attribute_shop.id_shop = 1 AND product_attribute_shop.default_on = 1)
WHERE product_shop.`active` = 1
AND (( product_shop.`id_product` = 38) OR( product_shop.`id_product` = 40) OR( product_shop.`id_product` = 41)................all products
AND p.`id_product` IN (
SELECT cp.`id_product`
FROM `awfps_category_group` cg
LEFT JOIN `awfps_category_product` cp ON (cp.`id_category` = cg.`id_category`)
WHERE cg.`id_group` IN (3)
)
AND product_shop.`visibility` IN ("both", "catalog")
GROUP BY product_shop.id_product
ORDER BY RAND() LIMIT 1
I got the solution. I searched for the bug in debugging tool and found some clues. The error was for special blocks module. When you have a lot of products in the special category or in other words if you have applied catalog price discount to a lot of products then the special block module retrieves all products with the same category and chooses a particular to show in the special block. Disabled it and it's working. This part of the code may need to be modified. I've tried to create an issue but didn't succeeded when writing this post. May create that later.
When i'll try create some but when i call it appears the error 1356:
Creating the View
CREATE VIEW monitoring_consult AS (
SELECT
m.id,
account.valor AS 'phone_number',
IF((c.valor REGEXP '^[0-9]+$' OR c.valor IS NULL) AND cn.short_name IS NOT NULL, cn.short_name, c.valor) AS 'category',
IF(pn.id IS NOT NULL, pn.id, p.valor) AS 'provider',
n.valor AS 'nominal',
m.last_page,
pn.name AS 'provider_name',
IF(pay.valor is null, 'Uncompleted', pay.valor) AS 'payment',
timeEnd,
DATE_FORMAT(m.timeEnd, '%d/%m/%Y') as 'date'
FROM
monitoring AS m
LEFT JOIN feature AS account ON m.id = account.id AND account.valor IS NOT NULL AND (account.page = 'PV') AND account.type = 'send'
LEFT JOIN feature AS c ON m.id = c.id_monitoring AND c.valor IS NOT NULL AND (c.page = 'MA' OR c.page = 'IN') AND c.type = 'select'
LEFT JOIN feature AS p ON m.id = p.id_monitoring AND p.page = 'PO' AND p.valor IS NOT NULL AND p.type = 'select'
LEFT JOIN feature AS n ON m.id = n.id_monitoring AND n.valor IS NOT NULL AND n.page = 'OAP' AND n.type = 'select'
LEFT JOIN feature AS pay ON m.id = pay.id_monitoring AND m.last_page = 'OK' AND pay.type = 'userAction' AND pay.name = 'paymentStatus' AND pay.valor = 'Completed'
LEFT JOIN terminais AS term ON m.id_terminal = term.id
LEFT JOIN provider AS pn ON (p.valor = pn.id) OR (c.valor REGEXP '^[0-9]+$' AND c.valor = pn.id)
LEFT JOIN category AS cn ON pn.id_category = cn.id
group by m.id
having category is not null
)
Calling the view:
select * from monitoring_consult
Return:
Error Code: 1356. View 'qiwi.monitoring_consult' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
Mysql Version - 5.5.32-log
Do someone know why this happened?
this particular problem happen to me every time i imported a mysqldump export, with automatic views creation inside it,
such problem came out because of the creation of the view in the mysqldump (when you reimport again), with "SQL SECURITY DEFINER",
i don't known if it is a mysql bug, but for me deleting and applying new permission to the view, does not solve the problem, recreating the view without the "SQL SECURITY DEFINER", solve my problem, i hope this is your case.
Ciao.
These are the cases
MySQL loggined user has not the privilege view the monitoring_consult view
Any of your joined table not exist
Any of your field that you are trying fetch not exist ( You might be deleted )
I was getting the same error code and was able to pin it down somewhat. It appears to arise when an object two (or more?) levels down is no longer available. Here is some code to recreate the issue.
create table `table1` (`id` int(11), `col1` varchar(16);
insert into `table1` (`id`, `col1`) values (1, 'Foo'), (2, 'Bar');
create view `view_sub` as SELECT `id`, `col1` from `table1`;
# if you drop here you'll get error code 1146: table1 doesn't exist
create view `view_err` as SELECT `id`, `col1` from `view_sub`;
drop table `table1`;
select * from `view_err`
# should get you error code 1356: references invalid table(s), etc
I don't know if anything in your from clause is a view, but the (what appears to be) typo of terminais may be causing it.
When creating the view, try to specify a definer like this:
CREATE
ALGORITHM = UNDEFINED
DEFINER = `user`#`%`
SQL SECURITY DEFINER
VIEW `monitoring_consult` AS ...
where the DEFINER usermust have the appropriate rights to any table that is linked to the view
Hi I got this error after changing my database model. Happened that an existing view referenced non existing fields.
So the solution was delete the current view and create a new one, considering the new model instead of focusing on user privileges.
Hope it helps to someone :)
I had the same problem. While I still don't know what it caused the problem, because none of the tables the view uses had been changed.
My solution was to drop the old view and create a new one this time I specified at the top of my view the following.
use databasename;
This message can sometimes be misleading. I was getting the same warning even though i had made sure that the definer user had the correct permissions and all the referenced tables/fields were OK.
After running
show create view viewName;
I noticed that the output contained 1 warning so after that I run
show warnings;
And that showed me the actual problem.
OK, first-off I admit MySQL Syntax has never been my strongest point. So, here I am.
Urls :
ID Url Code
===============================================
1 http://www.google.com Abcd
2 http://www.freetemplates4u.com Efgh
3 ...
Posts :
ID Title Address
===============================================
1 Some Title 1 http://mize.it/Abcd
2 Some Title 2 http://mize.it/Efgh
3 ...
I want to create a query to fetch the following table
Title Url
=======================================================
Some Title 1 http://www.google.com
Some Title 2 http://www.freetemplates4u.com
In a few words :
Take the Url-Code pairs from Urls table
Search for http://mize.it/+Code in the Posts table (in the Address field)
Combine the final Title and Url in a result table.
I know it has something to do with joins and concatenation, but I'm definitely lost.
SIDENOTE : I don't care neither about my current database's structure, nor about performance issues. All I want is to transfer existing data, from the existing database (without having to alter it), to my new website's database (under a totally different format/structure).
You should change your DB-Design, this query will have a poor performance since mysql has to do a full tablescan.
Try adding a code column in your Posts table hat has the right value (populate it on insert/update) and add an index to Code (both tables).
Now you should be able to do.
SELECT Posts.Title, Urls.Url
FROM Posts
INNER JOIN Urls ON Post.Code = Urls.Code
Update:
If the first part of the url is always the same, this will work
SELECT Post.Title, Urls.Url
FROM Posts
INNER JOIN Urls ON Post.Adress = CONCAT('http://mize.it/', Urls.Code)
TRY
SELECT p.title,x.url
FROM Posts p
INNER JOIN ( SELECT url, CONCAT('http://mize.it/',code) AS xcode FROM Urls ) x
ON (x.xcode = p.address)
Working DEMO
This is a different approch, it took a while for me to test it.
Since your Address field contains complete url and we only need to match what is after / so we can replace actual url with nothing (I assume url is always the same) and have string ready to be matched with Code field.
SELECT b.Title, a.URL
FROM Url a
LEFT JOIN Posts b
ON a.Code = REPLACE(b.Address, 'http://mize.it/', '')
ORDER BY a.ID ASC
Check following query.
select m1.Url, m2.Title from Urls as m1, Posts as m2
where m2.address like 'http://mize.it/%'
I'm trying to get all articles that are the current/latest articles in Mediawiki 1.16.0. I need to do this in phpMyadmin and make a dump from those results.
my SQL:
SELECT
page.page_title, page.page_latest
, revision.rev_id, revision.rev_text_id
, text.old_id, text.old_text
FROM page, revision, text
WHERE rev_id = page_latest AND rev_text_id = old_id
I get the image names also but not a problem. I feel that this SQL above is not getting the latest version of the articles.
If there is a way to not show image names and redirects in the results it would also help.
First of all please don't use that ugly implicit join syntax. It's confusing and error-prone.
Change it to this:
SELECT
page.page_title, page.page_latest
, revision.rev_id, revision.rev_text_id
, text.old_id, text.old_text
FROM page
INNER JOIN revision ON (rev_id = page_latest)
INNER JOIN text ON (rev_text_id = old_id)
Now you can see why: it's getting all pages. There is no where clause, there are just join clauses.
This is the DB layout: http://upload.wikimedia.org/wikipedia/commons/b/b7/MediaWiki_database_schema_1-17_%28r82044%29.png
And here are the description of the fields in the various tables:
http://www.mediawiki.org/wiki/Manual:Database_layout
Revised query
SELECT
p.page_title, p.page_latest
, MAX(revision.rev_id) as rev_id, revision.rev_text_id
, text.old_id, text.old_text
FROM page p
INNER JOIN revision r ON (r.rev_id = p.page_latest)
INNER JOIN `text` t ON (r.rev_text_id = t.old_id)
WHERE p.page_is_redirect = 0 AND p.page_namespace <> 6 /*NS_IMAGE = 6*/
GROUP BY p.page_latest
ORDER BY p.page_title
This filters out the redirects and excludes the pages where namespace = ns_image.
I'm not 100% sure though 'cause I don't have MediaWiki to test.