Running SQL Queries on the Moodle Database

Post on 15-Apr-2017

1,130 views 4 download

transcript

Running SQL Queries on the Moodle DatabaseAn overview

18 November 2016

Tools available

• Moodle Adminer• Ad-hoc Database Queries• Configurable Reports • PHP MyAdmin

Moodle Adminer

• The ‘work horse’• SQL in, information out• Aimed at Admins• Powerful for large queries• Slick authoring of queries• Robust browsing of tables

• So what’s the catch?

Moodle Adminer

Great so I can edit the database directly?Technically speaking yes…

Moodle Adminer

Installation and set up

The plugin installs like any other Moodle plugin, in the local folder and can be found at Site Administration > Server

Top Tip: If your Database Server has multiple databases, consider using moodleuser or similar in your config.php(create if needed)

Moodle Adminer

Demo

SELECT fullname, shortname FROM mdl_course ORDER BY fullname ASC

Ad Hoc SQL

Installation and set up

The plugin installs like any other Moodle plugin, in the reports folder and can be found at Site Administration > Reports

Ad Hoc SQL

• Write once, run many• Great for delegating running of queries to curriculum

managers• Not 100% foolproof• Elegant• Easy to use• Timer and Email utilisation

Ad Hoc SQL

Configurable Reports

• Very user friendly• Elegantly formatted output• Can be applied at course level as a block

Configurable Reports

Installation and set up

The plugin installs like any other Moodle plugin, in the block folder and can be added at course level

PHP My Admin

Installation and set up

Installed as a fully fledged application at server level.

Managing the Databases

Dumps

We do this through command line

mysqldump –u root –p –h localhost moodle > dump.sql

-v (verbose mode)

Managing the Databases

Find and Replace

We do this through command line, but the replace tool is also useful

sed –i ‘s/moodle.westcollegescotland.ac.uk/moodle14.westcollegescotland.ac.uk/g’ ./dump.sql

(sed is a Linux tool)

Managing the Databases

Managing the Databases

Imports

We do this through command line too

mysql –u root –p –h localhost moodle < dump.sql

-v (verbose mode)