summaryrefslogtreecommitdiff
path: root/topics/setting-up-local-development-database.gmi
blob: 1f844c388f11c60fa937fa2b45dcda9ccb1d2352 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# Setting up Local Development Database

## Introduction

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

* An assumption is made that the GeneNetwork2 profile is in ~/opt/gn_profiles/gn2_latest for the purposes of this documentation. Please replace as appropriate.
* We install the database files under ~/genenetwork/mariadb. Change as appropriate.

## Setup Database Server

Setup directories

```
mkdir -pv ~/genenetwork/mariadb/var/run
mkdir -pv ~/genenetwork/mariadb/var/lib/data
mkdir -pv ~/genenetwork/mariadb/var/lib/mysql
```

Setup default my.cnf

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

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

Install the database

```
~/opt/gn_profiles/gn2_latest/bin/mysql_install_db \
    --defaults-file=~/genenetwork/mariadb/my.cnf
```

Running the daemon:

```
~/opt/gn_profiles/gn2_latest/bin/mysqld_safe \
    --defaults-file=~/genenetwork/mariadb/my.cnf
```

Connect to daemon

```
~/opt/gn_profiles/gn2_latest/bin/mysql \
    --defaults-file=~/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

```
$ ~/opt/gn_profiles/gn2_latest/bin/mysql \
    --defaults-file=~/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:

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

and enter the password you provided.


## Setting up the Small Database

Download the database from

=> http://ipfs.genenetwork.org/ipfs/QmRUmYu6ogxEdzZeE8PuXMGCDa8M3y2uFcfo4zqQRbpxtk

Say you downloaded the file in ~/Downloads, you can now add the database to your server.

First stop the server:

```
$ ps aux | grep mysqld # get the process ids
$ kill -s SIGTERM <pid-of-mysqld> <pid-of-mysqld_safe>
```

Now extract the database archive in the mysql data directory:

```
$ cd ~/genenetwork/mariadb/var/lib/data
$ p7zip -k -d ~/Downloads/db_webqtl_s.7z
```

Now restart the server:

```
~/opt/gn_profiles/gn2_latest/bin/mysqld_safe \
    --defaults-file=~/genenetwork/mariadb/my.cnf
```

Then update the databases

```
$ ~/opt/gn_profiles/gn2_latest/bin/mysql_upgrade \
    --defaults-file=~/genenetwork/mariadb/my.cnf \
    --user=frederick --password --force
```

and login as the administrative user:

```
$ ~/opt/gn_profiles/gn2_latest/bin/mysql \
    --defaults-file=~/genenetwork/mariadb/my.cnf \
    --user=$(whoami) --password
```

and grant the privileges to your normal user:

```
MariaDB [mysql]> GRANT ALL PRIVILEGES ON db_webqtl_s.* TO 'webqtlout'@'localhost';
```

now logout as the administrative user and log back in as the normal user

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

MariaDB [db_webqtlout_s]> SELECT * FROM ProbeSetData LIMIT 20;
```

verify you see some data.

### A Note on Connection to the Server

So far, we have been connecting to the server by specifying --defaults-file option, e.g.

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

which allows connection via the unix socket.

We could drop that specification and connect via the port with:

```
~/opt/gn_profiles/gn2_latest/bin/mysql \
    --user=webqtlout --host=127.0.0.1 --port=3307 --password db_webqtlout_s
```

In this version, the host specification was changed from
```
--host=localhost
```
to
```
--host=127.0.0.1
```

whereas, the **--defaults-file** file specification was dropped and a new **--port** specification was added.