Project

General

Profile

Database Server Installation Shared » History » Version 18

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

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