Project

General

Profile

Database Server Installation Shared » History » Version 19

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