Create Moodle site database: Difference between revisions
m (→See also) |
(added easier setup instructions for mysql DB) |
||
Line 30: | Line 30: | ||
====Using the command line==== | ====Using the command line==== | ||
If you have access to Unix or Windows command lines then you can do the same sort of thing by typing commands. You should do this, if you want to use a MySQL database, using the MySQL Client program as follows (commands which you type-in are shown in bold): | If you have access to Unix or Windows command lines then you can do the same sort of thing by typing commands. | ||
====MYSQL==== | |||
You should do this, if you want to use a MySQL database, using the MySQL Client program as follows (commands which you type-in are shown in bold): | |||
- Start the MySQL Client program: | - Start the MySQL Client program: | ||
Line 81: | Line 85: | ||
Enter password: | Enter password: | ||
# | # | ||
If you want to run all this at once without so many commands then you can also do something like this (just copy and paste these lines into the mysql command line): | |||
create database moodle default character set utf8; | |||
grant all privileges on moodle.* to 'moodleuser'@'localhost' identified by 'yourpassword'; | |||
flush privileges; | |||
quit | |||
====POSTGRES==== | |||
And some example command lines for those who wish to use a PostgreSQL database: | And some example command lines for those who wish to use a PostgreSQL database: |
Revision as of 13:03, 29 April 2009
This page requires a review. Please do so and remove this template when finished.
- Warning: Bear in mind that, as of Moodle version 1.5.x, Moodle doesn't work with MySQL 5.x's strict mode setting (STRICT_TRANS_TABLES and/or STRICT_ALL_TABLES) -- see forum discussion. So if you are using MySQL 5.x, edit MySQL's configuration file (called "my.ini" in Windows and "my.cnf" on Unix/Linux) and comment out that option or set it to
sql-mode=
. You have to restart MySQL after changing this setting.
If you do not have access to your server, use PHPMyAdmin (or another MySQL client) and enter the commandSET @@global.sql_mode=
;
(be sure to use single quotes, and don't forget the semicolon).
- Warning: Bear in mind that, as of Moodle version 1.5.x, Moodle doesn't work with MySQL 5.x's strict mode setting (STRICT_TRANS_TABLES and/or STRICT_ALL_TABLES) -- see forum discussion. So if you are using MySQL 5.x, edit MySQL's configuration file (called "my.ini" in Windows and "my.cnf" on Unix/Linux) and comment out that option or set it to
Using a hosted server
If you are using a webhost, they will probably have a control panel web interface for you to create your database. The cPanel system is one of the most popular of these. To create a database using cPanel:
|
Continue with Creating the data directory
Using a SQLite database
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. Moodle 2.0 offers experimental support for SQLite3 database installations. In this case, no database setup is required. The database file will be created by the installation script. By default, the database file will be store in Moodle's data directory (see Creating the data directory). During install, the web server must have write access on the directory where the database file will be stored. After installation, the web server must have read-write access to the database file. Continue with Creating the data directory |
Using the command line
If you have access to Unix or Windows command lines then you can do the same sort of thing by typing commands.
MYSQL
You should do this, if you want to use a MySQL database, using the MySQL Client program as follows (commands which you type-in are shown in bold):
- Start the MySQL Client program:
#mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 to server version: 5.0.22-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql>
- The prompt changes to "mysql>" to indicate that you are now working in the MySQL Client program. When working in MySQL, all commands which you type-in must end in a semi-colon. (If you hit the Enter key without the final semi-colon, you'll get the line continuation symbol '->'; this is your second chance to type the semi-colon and hit Enter.)
- Begin by checking for any existing databases called "moodle" - if there are any you should change the name in all the commands which follow:
mysql> SHOW DATABASES; +-------------------------+ | Database | +-------------------------+ | information_schema | | mysql | | test | +-------------------------+ 3 rows in set (0.03 sec)
- Create a database to store the Moodle tables. We'll call this "moodle", as there are none with that name already in the above list, but change it if you need to.
mysql> CREATE DATABASE moodle; Query OK, 1 row affected (0.00 sec)
- Change the default character set and collation of the "moodle" database to UTF8. Leave this out if you are installing Moodle 1.5 or earlier):
mysql> ALTER DATABASE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; Query OK, 1 row affected (0.00 sec)
- Create a username and password to access the database "moodle" and grant database access permissions. We'll call the user "moodleuser" and set the password as "yourpassword". It's a good idea to change these for your installation however most people keep the username as "moodleuser". Remember the username and password you have set, as you'll need it in the configuration screens later. This is a long command so has been split over several lines by pressing the Return key.
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES, -> DROP,INDEX,ALTER ON moodle.* -> TO moodleuser@localhost IDENTIFIED BY 'yourpassword'; Query OK, 0 rows affected (0.01 sec)
- Security Warnings: Never leave the password as the one shown here. Make sure you have a strong password (a mixture of letters and numbers, upper and lower case). Avoid granting "ALL" permissions on the database.
- Note: For MySQL 4.0.1 or earlier, you don't need the CREATE TEMPORARY TABLES permission.
- Exit the MySQL Client program:
mysql> QUIT Bye #
- Reload the grant tables using the mysqladmin program:
#mysqladmin -u root -p reload Enter password: #
If you want to run all this at once without so many commands then you can also do something like this (just copy and paste these lines into the mysql command line):
create database moodle default character set utf8; grant all privileges on moodle.* to 'moodleuser'@'localhost' identified by 'yourpassword'; flush privileges; quit
POSTGRES
And some example command lines for those who wish to use a PostgreSQL database:
# su - postgres > psql -c "create user moodleuser createdb;" template1 > psql -c "alter user moodleuser with encrypted password 'yourpassword';" template1 > psql -c "create database moodle with encoding 'unicode';" -U moodleuser template1 > psql -c "alter user moodleuser nocreatedb;" template1 > su - root # /etc/init.d/postgresql reload
If the Postgres create database command above (>psql -c "create database moodle...") gives an error message you may want to try:
psql -c "create database moodle with template=template1 encoding = 'unicode' owner = moodleuser
location = '/var/mydata';"
If the create database command asks you for a password, run the line containing 'encrypted password' first before proceeding.
See also
- Installing Moodle
- Step-by-step instructions on installation for Ubuntu(Debian)