Project

General

Profile

Database Server Installation Shared » History » Version 21

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