test
[hcoop/zz_old/ikiwiki] / UsingDatabases.mdwn
CommitLineData
ee25310d 1## page was renamed from UseDatabases\r
2Previously, database creation needed admin intervention. We now wrote 'dbtool', however, to leave database management to the users themselves. This is possible because database files, kept in /home/<dbtype> (such as /home/mysql/), have proper filesystem permissions. They are set-gid to the users' primary group, so the sizes of users' databases enter their filesystem quota calculation.\r
3\r
4= MySQL =\r
5== Database creation ==\r
6The databases you select for creation will be prefixed with your username, to avoid any name clashes. In other words, if you ask for a database 'gis', the actual database created will be '<username>_gis'.\r
7\r
8When the database is created, all privileges on it are granted to the user owning them, except the privilege to grant permissions to other users.\r
9\r
10Let's see an invocation of dbtool:\r
11\r
12''' dbtool create <dbtype> <password> <database ...> '''\r
13\r
14Here's an example:\r
15\r
16''' dbtool create mysql myPass12.4 gis '''\r
17\r
18At this point, MySQL database '<username>_gis' has been created, and <username>@'''localhost''' is given permission to connect to it using password 'myPass12.4'. An important thing to remember here is that there is, by default, one password for all databases! If you create two MySQL databases, pick the same password for them or the second one will overwrite the first database password.\r
19\r
20== Load database ==\r
21To load a database, use:\r
22'''mysql -p <username>_gis < gis.sql'''\r
23== Connecting to the database ==\r
24You can always connect to the databases using appropriate command line tools:\r
25\r
26''' mysql -p <dbname> '''\r
27\r
28Upon typing in the password, mysql client tool will start up and connect to <dbname>. You can, however, create ~/.my.cnf to automate the "login":\r
29\r
30{{{\r
31[mysql]\r
32user = <username>\r
33password = myPass12.4 }}}\r
34Just make sure the file is mode 0600: '''chmod 0600 ~/.my.cnf''', and omit ''-p'' from further {{{mysql}}} invocations.\r
35\r
36== Database removal ==\r
37You can remove your own databases by invoking appropriate databases' command line tools. Here's a MySQL example:\r
38\r
39''' mysql -e 'drop database <username>_gis' '''\r
40\r
41Keep in mind that database permissions are not removed. In other words, once you drop the database, you can re-create it without invoking dbtool:\r
42\r
43''' mysql -e 'create database <username>_gis' '''\r
44\r
45= PostgreSQL =\r
46You can create Postgres databases in a similar way. The main difference is that you never provide a password to {{{dbtool}}}. While MySQL doesn't provide any reasonable non-password-based authentication option, PostgreSQL has the nice ident scheme, where processes authenticate to databases based on their owning UNIX user. Since this avoids adding an extra opportunity for password-guessing, we only allow Postgres authentication via this method.\r
47\r
48The following command line would create database {{{<username>_test}}}:\r
49\r
50''' dbtool create postgres test '''\r
51\r
52Then you could connect to your database:\r
53\r
54''' psql <username>_test '''\r