Project

General

Profile

Database Server Installation Shared » History » Version 12

Neil Voss, 05/12/2010 08:25 AM

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 10 Neil Voss
ls /usr/share/mysql/my*
37 11 Neil Voss
38 1 Amber Herold
    /usr/share/mysql/my-huge.cnf
39
    /usr/share/mysql/my-innodb-heavy-4G.cnf
40
    /usr/share/mysql/my-large.cnf
41
    /usr/share/mysql/my-medium.cnf
42
    /usr/share/mysql/my-small.cnf
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
 # Copy my-huge.cnf to my.cnf
48
<pre> 
49 10 Neil Voss
sudo cp -v /usr/share/mysql/my-huge.cnf /etc/my.cnf 
50 4 Amber Herold
</pre>
51 10 Neil Voss
52 6 Amber Herold
 # Edit /etc/my.cnf to add or change query cache variables like these:
53 1 Amber Herold
<pre>
54 11 Neil Voss
query_cache_type= 1
55
query_cache_size = 100M
56
query_cache_limit= 100M
57 1 Amber Herold
</pre>
58 10 Neil Voss
59 8 Anchi Cheng
 # Search for the text default-storage-engine in /etc/my.cnf.  If it exists and is set to other than MyISAM, you should change it to:
60 1 Amber Herold
<pre>
61 11 Neil Voss
default-storage-engine=MyISAM
62 9 Anchi Cheng
</pre>
63 10 Neil Voss
64 1 Amber Herold
h3. 5. start MySQL Server
65
66 10 Neil Voss
For CentOS/Fedora/RHEL system use the service command:
67
68 1 Amber Herold
<pre>
69 10 Neil Voss
sudo /sbin/service mysqld start
70 1 Amber Herold
</pre>
71
72 10 Neil Voss
For other Unix systems:
73
74
<pre>
75
sudo /etc/init.d/mysqld start
76
</pre>
77
78 12 Neil Voss
or on some installations,
79 1 Amber Herold
80
<pre>
81 10 Neil Voss
sudo /etc/init.d/mysql start
82 1 Amber Herold
</pre>
83
84
For future reference: start | stop | restart MySQL Server with similar commands:
85
86
<pre>
87 10 Neil Voss
sudo /etc/init.d/mysqld start
88
sudo /etc/init.d/mysqld stop
89
sudo /etc/init.d/mysqld restart
90
sudo /sbin/service mysqld start
91
sudo /sbin/service mysqld stop
92
sudo /sbin/service mysqld restart
93 1 Amber Herold
</pre>
94
95 12 Neil Voss
If you want to start MySQL automatically at boot
96 1 Amber Herold
97
<pre>
98 10 Neil Voss
sudo chkconfig mysql on
99 1 Amber Herold
</pre>
100
101
h3. 6. For future reference, the database location will be:
102
103 10 Neil Voss
<pre>
104
ls /var/lib/mysql
105 11 Neil Voss
    ibdata1  ib_logfile0  ib_logfile1  mysql  mysql.sock  test
106 1 Amber Herold
</pre>
107
108
h3. 7. Create the Leginon database, call it leginondb
109 3 Amber Herold
110 1 Amber Herold
<pre>
111 10 Neil Voss
sudo mysqladmin create leginondb
112 1 Amber Herold
</pre>
113
114
h3. 8. Create the Project database, call it projectdb
115
116
<pre>
117
sudo mysqladmin create projectdb
118
</pre>
119
120
h3. 9. Connect to mysql db
121
122 11 Neil Voss
If starting from scratch the mysql root user will have no password. To set the root password use the command: @sudo mysqladmin -u root password NEWPASSWORD@
123
124 12 Neil Voss
<pre><code class="perl">
125 11 Neil Voss
mysql -u root -p mysql
126 12 Neil Voss
</code></pre>
127 1 Amber Herold
128 11 Neil Voss
<pre>
129
mysql> select user, password, host from user;
130 1 Amber Herold
      +------+----------+-----------+
131
      | user | password | host      |
132
      +------+----------+-----------+
133
      | root |          | localhost |
134
      | root |          | host1     |
135
      |      |          | host1     |
136
      |      |          | localhost |
137
      +------+----------+-----------+
138
      4 rows in set (0.00 sec)
139
</pre>
140
141
h3. 10. Create user
142
143
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
144 3 Amber Herold
145 1 Amber Herold
<pre>
146 10 Neil Voss
mysql> create user usr_object@'localhost';
147
mysql> grant all privileges on leginondb.* to usr_object@'localhost';
148
mysql> grant all privileges on projectdb.* to usr_object@'localhost';
149 1 Amber Herold
</pre>
150
151
Similarly,
152 3 Amber Herold
153 1 Amber Herold
<pre>
154 10 Neil Voss
mysql> create user usr_object@'%';
155
mysql> grant all privileges on leginondb.* to usr_object@<host.mydomain.edu>;
156
mysql> grant all privileges on projectdb.* to usr_object@<host.mydomain.edu>;
157 1 Amber Herold
</pre>
158
159
Next, give create and access privileges for the processing databases which begin with "ap".
160 3 Amber Herold
161 1 Amber Herold
<pre>
162 10 Neil Voss
// if your web host is local
163
mysql> grant all privileges on `ap%`.* to usr_object@localhost; 
164
// for all other hosts if you are accessing the databases from another computer
165
mysql> grant all privileges on `ap%`.* to usr_object@<host.mydomain.edu>;       
166 1 Amber Herold
</pre>
167
168
h3. 11. Change Root password
169
170 12 Neil Voss
<pre>
171 1 Amber Herold
172 10 Neil Voss
mysql> update user set password=password('your_own_root_password') where user="root";
173
Query OK, 2 rows affected (0.01 sec)
174
Rows matched: 2  Changed: 2  Warnings: 0
175
176
mysql> flush privileges;
177
mysql>^D or exit;
178 12 Neil Voss
</pre>
179 10 Neil Voss
180 3 Amber Herold
181 1 Amber Herold
From now on, you will need to specify the password to connect to the database as root user like this:
182 3 Amber Herold
183 1 Amber Herold
<pre>
184
      >mysql -u root -p mysql
185
</pre>
186
187
h3. 12. Check MySQL variables
188
189
<pre>
190
      >mysql -u usr_object leginondb
191
192
      mysql> SHOW VARIABLES LIKE 'query%';
193
      +------------------------------+-----------+
194
      | Variable_name                | Value     |
195
      +------------------------------+-----------+
196
      | ft_query_expansion_limit     | 20        |
197
      | have_query_cache             | YES       |
198
      | long_query_time              | 10        |
199
      | query_alloc_block_size       | 8192      |
200
      | query_cache_limit            | 104857600 | <<---This should correspond to your change
201
      | query_cache_min_res_unit     | 4096      |
202
      | query_cache_size             | 104857600 | <<---This should correspond to your change
203
      | query_cache_type             | ON        | <<---This should correspond to your change
204
      | query_cache_wlock_invalidate | OFF       |
205
      | query_prealloc_size          | 8192      |
206
      +------------------------------+-----------+
207
      10 rows in set (0.00 sec)
208
209
      mysql> exit;
210
</pre>
211
212
h3. 13. Make sure MySQL is running
213
214
<pre>
215
      prompt:~> mysqlshow
216
      +--------------+
217
      | Databases    |
218
      +--------------+
219
      | mysql        |
220
      | leginondb    |
221
      | projectdb    |
222
      +--------------+
223
</pre>
224 3 Amber Herold
225 1 Amber Herold
h3. 14. Or check with the following php script (if already installed)
226
227
<pre>
228
      <?
229 3 Amber Herold
      mysql_connect('your_host.your_institute.edu', 'usr_object', '','leginondb');
230 1 Amber Herold
      echo mysql_stat();
231 3 Amber Herold
      ?> 
232 1 Amber Herold
</pre>
233 3 Amber Herold
234 1 Amber Herold
Output:
235 3 Amber Herold
236 1 Amber Herold
<pre>
237
       Uptime: 1452562 Threads: 1 Questions: 618 Slow queries: 0 Opens: 117 Flush tables: 1 Open tables: 106 Queries per second avg: 0.000
238
</pre>
239
240
h2. Configure phpMyAdmin 
241
242
Edit the phpMyAdmin config file:
243
244
<pre>
245
$ sudo vi /etc/phpMyAdmin/config.inc.php
246
</pre> 
247
248
and change the following lines:
249
250
<pre>
251
$cfg['Servers'][$i]['AllowRoot']     = FALSE;
252
</pre>
253
254
Edit the phpMyAdmin apache config file:
255
256
<pre>
257 12 Neil Voss
$ sudo $EDITOR /etc/httpd/conf.d/phpMyAdmin.conf
258 1 Amber Herold
</pre>
259
260
and change the following lines:
261
262
*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
263
264
<pre>
265
<Directory /usr/share/phpMyAdmin/>
266
   order deny,allow
267
   deny from all
268
   allow from 127.0.0.1
269
   allow from YOUR_IP_ADDRESS
270
</Directory>
271
</pre>
272
273
To test the PHPMyAdmin configuration, point your browser to http://YOUR_IP_ADDRESS/phpmyadmin.