Project

General

Profile

Database Server Installation Shared » History » Version 3

Amber Herold, 04/20/2010 12:21 PM

1 1 Amber Herold
h1. Database Server Installation
2
3
4
h2. Install MySQL 
5
6
The following is for the computer that hosts the databases. This involves installing MySQL server and creation/configuration of the leginondb and projectdb databases.
7
8
Note: You may already have MySQL Server and Client installed. Check by typing mysql at the command line. 
9
If you see a MySQL prompt (mysql>), skip steps 1 and 2.
10
 
11
h3. 1. Install MySQL-Server
12
13
* Use your package installer (yum, zypper, YaST) if available.
14
            OR
15
* Download the latest MySQL-server RPM for Linux from www.mysql.com
16
* Install the MySQL-server rpm:
17
18
    rpm -Uvh MySQL-server-5.0.xx-y.i386.rpm
19
20
(substitute correct version numbers)
21
22
h3. 2. Install MySQL-Client
23
24
* Use your package installer (yum, zypper, YaST) if available.
25
            OR
26
* Download the latest MySQL-client RPM for Linux from www.mysql.com
27
* Install the MySQL-client rpm:
28
29
    rpm -Uvh MySQL-client-5.0.xx-y.i386.rpm
30
31
(substitute correct version numbers)
32
33
h3. 3. MySQL configuration file is usually located in /usr/share/mysql. There are several examples there:
34
35 3 Amber Herold
<pre>
36 1 Amber Herold
  > ls /usr/share/mysql/my*
37
    /usr/share/mysql/my-huge.cnf
38
    /usr/share/mysql/my-innodb-heavy-4G.cnf
39
    /usr/share/mysql/my-large.cnf
40
    /usr/share/mysql/my-medium.cnf
41
    /usr/share/mysql/my-small.cnf
42
  > 
43 3 Amber Herold
</pre>
44 1 Amber Herold
45
h3. 4. Configure my.cnf in /etc using my-huge.cnf as the template
46
47 3 Amber Herold
         1. <pre> > cp /usr/share/mysql/my-huge.cnf /etc/my.cnf </pre>
48 1 Amber Herold
49
         2. Edit /etc/my.cnf to add or change query cache variables like these:
50
            query_cache_type= 1
51
            query_cache_size = 100M
52
            query_cache_limit= 100M
53
54
h3. 5. start MySQL Server
55
56 3 Amber Herold
<pre>
57 1 Amber Herold
       >/etc/init.d/mysqld start
58 3 Amber Herold
</pre>
59 1 Amber Herold
60
on some installation,
61
62 3 Amber Herold
<pre>
63 1 Amber Herold
       >/etc/init.d/mysql start
64 3 Amber Herold
</pre>
65 1 Amber Herold
66
For future reference: start | stop | restart MySQL Server with similar commands:
67
68 3 Amber Herold
<pre>
69 1 Amber Herold
       >/etc/init.d/mysqld start
70
       >/etc/init.d/mysqld stop
71
       >/etc/init.d/mysqld restart
72 3 Amber Herold
</pre>
73 1 Amber Herold
74
If you want to start MySQL automatically at boot on SuSE
75
76 3 Amber Herold
<pre>
77 1 Amber Herold
       SuSE >chkconfig mysql on
78 3 Amber Herold
</pre>
79 1 Amber Herold
80
h3. 6. For future reference, the database location will be:
81
82 3 Amber Herold
<pre>
83 1 Amber Herold
      > cd /var/lib/mysql
84
      Directory: /var/lib/mysql
85
      > ls
86
      yourdbserver.pid
87
      ib_logfile0
88
      mysql
89
      mysql.sock
90
      test
91
      > 
92 3 Amber Herold
</pre>
93 1 Amber Herold
94
h3. 7. Create the Leginon database, call it leginondb
95
96 3 Amber Herold
<pre>
97 1 Amber Herold
       >mysqladmin create leginondb
98 3 Amber Herold
</pre>
99 1 Amber Herold
100
h3. 8. Create the Project database, call it projectdb
101
102 3 Amber Herold
<pre>
103 1 Amber Herold
       >mysqladmin create projectdb
104 3 Amber Herold
</pre>
105 1 Amber Herold
106
h3. 9. Connect to mysql db
107
108
<pre>
109
      >mysql mysql
110
111
      mysql> select user, password, host from user;
112
      +------+----------+-----------+
113
      | user | password | host      |
114
      +------+----------+-----------+
115
      | root |          | localhost |
116
      | root |          | host1     |
117
      |      |          | host1     |
118
      |      |          | localhost |
119
      +------+----------+-----------+
120
      4 rows in set (0.00 sec)
121
</pre>
122
123
h3. 10. Create user
124
125
Create and grant privileges to a user called usr_object for the databases on both the localhost and other hosts involved. For example, use wild card '%' for all hosts. You may also set specific privilege to the user. See MySQL Reference Manual for details
126
127 3 Amber Herold
<pre>
128 1 Amber Herold
      mysql> create user usr_object@'localhost';
129
      mysql> grant all privileges on leginondb.* to usr_object@'localhost';
130
      mysql> grant all privileges on projectdb.* to usr_object@'localhost';
131 3 Amber Herold
</pre>
132 1 Amber Herold
133
Similarly,
134
135 3 Amber Herold
<pre>
136 1 Amber Herold
      mysql> create user usr_object@'%';
137
      mysql> grant all privileges on leginondb.* to usr_object@'%';
138
      mysql> grant all privileges on projectdb.* to usr_object@'%';
139 3 Amber Herold
</pre>
140 1 Amber Herold
141
Next, give create and access privileges for the processing databases which begin with "ap".
142
143 3 Amber Herold
<pre>
144 1 Amber Herold
      // if your web host is local
145
      mysql> grant all privileges on `ap%`.* to usr_object@localhost; 
146
      // for all other hosts if you are accessing the databases from another computer
147
      mysql> grant all privileges on `ap%`.* to usr_object@`%`;       
148 3 Amber Herold
</pre>
149 1 Amber Herold
150
h3. 11. Change Root password
151
152
<pre>
153
      mysql> update user set password=password('your_own_root_password') where user="root";
154
      Query OK, 2 rows affected (0.01 sec)
155
      Rows matched: 2  Changed: 2  Warnings: 0
156
157
      mysql> flush privileges;
158
      mysql>^D or exit;
159
</pre>
160
161
From now on, you will need to specify the password to connect to the database as root user like this:
162
163 3 Amber Herold
<pre>
164 1 Amber Herold
      >mysql -u root -p mysql
165 3 Amber Herold
</pre>
166 1 Amber Herold
167
h3. 12. Check MySQL variables
168
169
<pre>
170
      >mysql -u usr_object leginondb
171
172
      mysql> SHOW VARIABLES LIKE 'query%';
173
      +------------------------------+-----------+
174
      | Variable_name                | Value     |
175
      +------------------------------+-----------+
176
      | ft_query_expansion_limit     | 20        |
177
      | have_query_cache             | YES       |
178
      | long_query_time              | 10        |
179
      | query_alloc_block_size       | 8192      |
180
      | query_cache_limit            | 104857600 | <<---This should correspond to your change
181
      | query_cache_min_res_unit     | 4096      |
182
      | query_cache_size             | 104857600 | <<---This should correspond to your change
183
      | query_cache_type             | ON        | <<---This should correspond to your change
184
      | query_cache_wlock_invalidate | OFF       |
185
      | query_prealloc_size          | 8192      |
186
      +------------------------------+-----------+
187
      10 rows in set (0.00 sec)
188
189
      mysql> exit;
190
</pre>
191
192
h3. 13. Make sure MySQL is running
193
194
<pre>
195
      prompt:~> mysqlshow
196
      +--------------+
197
      | Databases    |
198
      +--------------+
199
      | mysql        |
200
      | leginondb    |
201
      | projectdb    |
202
      +--------------+
203
</pre>
204
205
h3. 14. Or check with the following php script (if already installed)
206
207 3 Amber Herold
<pre>
208 1 Amber Herold
      <?
209
      mysql_connect('your_host.your_institute.edu', 'usr_object', '','leginondb');
210
      echo mysql_stat();
211
      ?> 
212 3 Amber Herold
</pre>
213 1 Amber Herold
214 3 Amber Herold
Output:
215 1 Amber Herold
216 3 Amber Herold
<pre>
217 1 Amber Herold
       Uptime: 1452562 Threads: 1 Questions: 618 Slow queries: 0 Opens: 117 Flush tables: 1 Open tables: 106 Queries per second avg: 0.000
218 3 Amber Herold
</pre>
219 1 Amber Herold
220
h2. Configure phpMyAdmin 
221
222
Edit the phpMyAdmin config file:
223
224
<pre>
225
$ sudo vi /etc/phpMyAdmin/config.inc.php
226
</pre> 
227
228
and change the following lines:
229
230
<pre>
231
$cfg['Servers'][$i]['AllowRoot']     = FALSE;
232
</pre>
233
234
Edit the phpMyAdmin apache config file:
235
236
<pre>
237
$ sudo vi /etc/httpd/conf.d/phpMyAdmin.conf
238
</pre>
239
240
and change the following lines:
241
242
*Note:* If you want to access phpMyAdmin from another computer, you can add it to its web access configuration file found as /etc/httpd/conf.d/phpMyAdmin.conf in a typical installation
243
244
<pre>
245
<Directory /usr/share/phpMyAdmin/>
246
   order deny,allow
247
   deny from all
248
   allow from 127.0.0.1
249
   allow from YOUR_IP_ADDRESS
250
</Directory>
251
</pre>
252
253
To test the PHPMyAdmin configuration, point your browser to http://YOUR_IP_ADDRESS/phpmyadmin.