summaryrefslogtreecommitdiff
path: root/topics/setting-up-local-development-database.gmi
blob: c2856a8374386f99a691cacb0c082ff4667e2bac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Setting up Local Development Database

## Introduction

You need to setup a quick local database for development without needing root permissions and polluting your environment.

* ${HOME} is the path to your home directory
* An assumption is made that the GeneNetwork2 profile is in ${HOME}/opt/gn_profiles/gn2_latest for the purposes of this documentation. Please replace as appropriate.
* We install the database files under ${HOME}/genenetwork/mariadb. Change as appropriate.

## Steps

Setup directories

```
mkdir -pv ${HOME}/genenetwork/mariadb/var/run
mkdir -pv ${HOME}/genenetwork/mariadb/var/lib/data
mkdir -pv ${HOME}/genenetwork/mariadb/var/lib/mysql
```

Setup default my.cnf

```
cat <<EOF > ${HOME}/genenetwork/mariadb/my.cnf
[client-server]
socket=${HOME}/genenetwork/mariadb/var/run/mysqld/mysqld.sock
port=3307

[server]
user=$(whoami)
socket=${HOME}/genenetwork/mariadb/var/run/mysqld/mysqld.sock
basedir=${HOME}/opt/gn_profiles/gn2_latest
datadir=${HOME}/genenetwork/mariadb/var/lib/data
ft_min_word_len=3
EOF
```

Install the database

```
${HOME}/opt/gn_profiles/gn2_latest/bin/mysql_install_db \
    --defaults-file=${HOME}/genenetwork/mariadb/my.cnf
```

Running the daemon:

```
${HOME}/opt/gn_profiles/gn2_latest/bin/mysqld_safe \
    --defaults-file=${HOME}/genenetwork/mariadb/my.cnf
```

Connect to daemon

```
${HOME}/opt/gn_profiles/gn2_latest/bin/mysql \
    --defaults-file=${HOME}/genenetwork/mariadb/my.cnf
```

Set up password for user

```
MariaDB [(none)]> USE mysql;
MariaDB [mysql]> ALTER USER '<your-username>'@'localhost' IDENTIFIED BY '<the-new-password>';
MariaDB [mysql]> FLUSH PRIVILEGES;
```

Now logout and login again with

```
$ ${HOME}/opt/gn_profiles/gn2_latest/bin/mysql \
    --defaults-file=${HOME}/genenetwork/mariadb/my.cnf --password mysql
```

enter the newly set password and voila, you are logged in and your user has the password set up.

Now, setup a new user, say webqtlout, and a default database they can connect to

```
MariaDB [mysql]> CREATE DATABASE webqtlout;
MariaDB [mysql]> CREATE USER 'webqtlout'@'localhost' IDENTIFIED BY '<some-password>';
MariaDB [mysql]> GRANT ALL PRIVILEGES ON webqtlout.* TO 'webqtlout'@'localhost';
```

Now logout, and log back in as the new webqtlout user:

```
/home/frederick/opt/gn_profiles/gn2_latest/bin/mysql \
    --defaults-file=/home/frederick/genenetwork/mariadb/my.cnf \
    --user=webqtlout --host=localhost --password webqtlout
```

and enter the password you provided.