Project

General

Profile

Database Server Installation Shared » History » Version 22

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