Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Running SQL Queries on the Moodle Database

5,916 views

Published on

Workshop delivered by James MacNee, West College Scotland for the Scottish Moodle User Group (SMUG).

Published in: Education

Running SQL Queries on the Moodle Database

  1. 1. Running SQL Queries on the Moodle Database An overview 18 November 2016
  2. 2. Tools available • Moodle Adminer • Ad-hoc Database Queries • Configurable Reports • PHP MyAdmin
  3. 3. 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?
  4. 4. Moodle Adminer Great so I can edit the database directly? Technically speaking yes…
  5. 5. 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)
  6. 6. Moodle Adminer Demo SELECT fullname, shortname FROM mdl_course ORDER BY fullname ASC
  7. 7. 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
  8. 8. 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
  9. 9. Ad Hoc SQL
  10. 10. Configurable Reports • Very user friendly • Elegantly formatted output • Can be applied at course level as a block
  11. 11. 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
  12. 12. PHP My Admin Installation and set up Installed as a fully fledged application at server level.
  13. 13. Managing the Databases Dumps We do this through command line mysqldump –u root –p –h localhost moodle > dump.sql -v (verbose mode)
  14. 14. 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.westcollege scotland.ac.uk/g’ ./dump.sql (sed is a Linux tool)
  15. 15. Managing the Databases
  16. 16. Managing the Databases Imports We do this through command line too mysql –u root –p –h localhost moodle < dump.sql -v (verbose mode)

×