Difference between revisions of "MySQL"

Jump to: navigation, search
(See also)
m (Get rid of databases forum link. [https://moodle.org/mod/forum/discuss.php?d=217775])
Line 42: Line 42:
* [[MariaDB]]
* [[MariaDB]]
* [http://www.mysql.com/ The MySQL homepage]
* [http://www.mysql.com/ The MySQL homepage]
* [http://moodle.org/mod/forum/view.php?id=45 Using Moodle databases forum]
* [http://en.wikipedia.org/wiki/MySQL Wikipedia article about ''MySQL'']
* [http://en.wikipedia.org/wiki/MySQL Wikipedia article about ''MySQL'']
* [http://forums.mysql.com/read.php?24,92131,92131 List of articles on MySQL performance tuning]
* [http://forums.mysql.com/read.php?24,92131,92131 List of articles on MySQL performance tuning]

Revision as of 15:42, 14 December 2013

MySQL is one of the supported databases that underpins a Moodle installation.

Installing MySQL

  • If you are running Linux your preference should be to install using your distributions package manager. This ensures you will get any available updates.
  • There are installers available for most popular operating systems at http://www.mysql.com/downloads/mysql/.
  • It is possible and reasonably straightforward to build mysql from source but it is not recommended (the pre-built binaries are supposedly better optimised).
  • Make sure you set a password for the 'root' user (see http://dev.mysql.com/doc/refman/5.0/en/default-privileges.html).
  • Consider installing and configuring my.cnf (the MySQL settings file) to suit your needs. The default configuration is usually very conservative in respect of memory usage versus performance.

Creating Moodle database

These are the steps to create an empty Moodle database. Substitute your own database name, user name and password as appropriate.

The instructions assume that the web server and MySQL server are on the same machine. In this case the 'dbhost' is 'localhost'. If they are on different machines substitute the name of the web server for 'localhost' in the following instructions and the 'dbhost' setting will be the name of the database server.

Command line

  • To create a database using the 'mysql' command line client, first log into MySQL
$ mysql -u root -p
Enter password: 

(Enter the password you previously set - or been given - for the MySQL 'root' user). After some pre-amble this should take you to the mysql> prompt.

  • Create a new database (called 'moodle' - substitute your own name if required). We recommend you use utf8_unicode_ci for collation.
mysql> CREATE DATABASE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
  • Add a user/password with the minimum needed permissions:

...which creates a user called 'moodleuser' with a password 'yourpassword'. Make sure you invent a strong password and resist the temptation to 'GRANT ALL'.


phpMyAdmin is a web based administration tool for MySQL. If this is available you can use it to create a new database. Make sure that you select 'UTF8' as the default character set.

See also