Project

General

Profile

Database Server Installation Shared » History » Version 42

Amber Herold, 05/17/2010 12:21 PM

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 38 Amber Herold
8 1 Amber Herold
 
9 42 Amber Herold
h3. 1 Install MySQL-Server and MySQL-Client
10 38 Amber Herold
11
*Note:* You may already have MySQL Server and Client installed. Check by typing mysql at the command line. 
12
If you see a MySQL prompt (mysql>), you may skip this step.
13 1 Amber Herold
14 15 Neil Voss
To install Mysql on Linux you have two options (the first option is better):
15 1 Amber Herold
16 15 Neil Voss
# Use your package installer (yum, zypper, YaST, apt-get). For example:
17
<pre>sudo yum install mysql mysql-server</pre>
18
# Download the latest MySQL-server package for Linux from http://www.mysql.com
19 1 Amber Herold
20 42 Amber Herold
h3. 2 Locate Example MySQL configuration files 
21 1 Amber Herold
22 42 Amber Herold
They are usually located in /usr/share/mysql.
23
24 1 Amber Herold
<pre>
25
ls /usr/share/mysql/my*
26 15 Neil Voss
    /usr/share/mysql/my-huge.cnf
27
    /usr/share/mysql/my-innodb-heavy-4G.cnf
28
    /usr/share/mysql/my-large.cnf
29
    /usr/share/mysql/my-medium.cnf
30
    /usr/share/mysql/my-small.cnf
31 20 Neil Voss
</pre>
32
If that does not work try the locate function
33
<pre>
34 15 Neil Voss
locate my | egrep "\.cnf$"
35
    /etc/my.cnf
36 1 Amber Herold
    /usr/share/mysql/my-huge.cnf
37
    /usr/share/mysql/my-innodb-heavy-4G.cnf
38
    /usr/share/mysql/my-large.cnf
39
    /usr/share/mysql/my-medium.cnf
40
    /usr/share/mysql/my-small.cnf
41 3 Amber Herold
</pre>
42 1 Amber Herold
43 42 Amber Herold
h3. 3 Configure my.cnf in /etc using my-huge.cnf as the template
44 1 Amber Herold
45 18 Neil Voss
# Copy my-huge.cnf to my.cnf
46 19 Neil Voss
<pre>sudo cp -v /usr/share/mysql/my-huge.cnf /etc/my.cnf</pre>
47 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):
48 1 Amber Herold
<pre>
49 39 Amber Herold
query_cache_type = 1
50 1 Amber Herold
query_cache_size = 100M
51 21 Neil Voss
query_cache_limit= 100M
52 1 Amber Herold
</pre>
53 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:
54 1 Amber Herold
<pre>default-storage-engine=MyISAM</pre>
55 10 Neil Voss
56 42 Amber Herold
h3. 4 Start the MySQL Server
57 1 Amber Herold
58 10 Neil Voss
For CentOS/Fedora/RHEL system use the service command:
59
60 1 Amber Herold
<pre>
61 10 Neil Voss
sudo /sbin/service mysqld start
62 1 Amber Herold
</pre>
63
64 10 Neil Voss
For other Unix systems:
65
66
<pre>
67
sudo /etc/init.d/mysqld start
68
</pre>
69
70 12 Neil Voss
or on some installations,
71 1 Amber Herold
72
<pre>
73 10 Neil Voss
sudo /etc/init.d/mysql start
74 1 Amber Herold
</pre>
75
76
For future reference: start | stop | restart MySQL Server with similar commands:
77
78
<pre>
79 10 Neil Voss
sudo /etc/init.d/mysqld start
80
sudo /etc/init.d/mysqld stop
81
sudo /etc/init.d/mysqld restart
82 1 Amber Herold
sudo /sbin/service mysqld start
83 10 Neil Voss
sudo /sbin/service mysqld stop
84
sudo /sbin/service mysqld restart
85 1 Amber Herold
</pre>
86
87 42 Amber Herold
h3. 5 Configure MySQL to start automatically at boot
88 1 Amber Herold
89
<pre>
90
sudo /sbin/chkconfig mysqld on
91
</pre>
92 23 Neil Voss
or for SuSe:
93
<pre>
94
sudo /sbin/chkconfig mysql on
95
</pre>
96 1 Amber Herold
97 42 Amber Herold
h3. 6 For future reference, the database location will be:
98 1 Amber Herold
99 10 Neil Voss
<pre>
100
ls /var/lib/mysql
101 1 Amber Herold
    ibdata1  ib_logfile0  ib_logfile1  mysql  mysql.sock  test
102
</pre>
103
104 42 Amber Herold
h3. 7 Create the Leginon database, call it leginondb
105 3 Amber Herold
106 10 Neil Voss
<pre>
107 1 Amber Herold
sudo mysqladmin create leginondb
108
</pre>
109
110 42 Amber Herold
h3. 8 Create the Project database, call it projectdb
111 1 Amber Herold
112
<pre>
113
sudo mysqladmin create projectdb
114
</pre>
115
116 42 Amber Herold
h3. 9 Connect to mysql db
117 11 Neil Voss
118 40 Amber Herold
If starting from scratch, the mysql root user will have no password. This is assumed to be the case and we will set it later.
119 1 Amber Herold
120 23 Neil Voss
<pre>
121 28 Neil Voss
mysql -u root mysql
122 23 Neil Voss
</pre>
123 1 Amber Herold
124 40 Amber Herold
You should see a mysql prompt: mysql>
125
126
You can view the current mysql users with the following command.
127 11 Neil Voss
<pre>
128 40 Amber Herold
select user, password, host from user;
129 1 Amber Herold
      +------+----------+-----------+
130
      | user | password | host      |
131
      +------+----------+-----------+
132
      | root |          | localhost |
133
      | root |          | host1     |
134
      |      |          | host1     |
135
      |      |          | localhost |
136
      +------+----------+-----------+
137
      4 rows in set (0.00 sec)
138
</pre>
139
140 42 Amber Herold
h3. 10 Create user
141 1 Amber Herold
142 41 Amber Herold
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 (@ALTER, CREATE, DROP, DELETE, INSERT, RENAME, SELECT, UPDATE@) privileges or @ALL@ privileges to the user. See MySQL Reference Manual for details. The following examples demonstrate some of the options available.
143 3 Amber Herold
144 36 Amber Herold
At the mysql prompt execute the following commands:
145 1 Amber Herold
<pre>
146 36 Amber Herold
CREATE USER usr_object@'localhost' IDENTIFIED BY 'YOUR PASSWORD';
147
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON leginondb.* TO usr_object@'localhost';
148
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON projectdb.* TO usr_object@'localhost';
149 1 Amber Herold
</pre>
150
151 41 Amber Herold
You may choose to use the following less secure version (no password and all privileges) of the commands above, however, we recommend not allowing the DROP and DELETE privileges.
152 1 Amber Herold
153 36 Amber Herold
At the mysql prompt execute the following commands:
154 24 Neil Voss
<pre>
155 36 Amber Herold
CREATE USER usr_object@'localhost';
156
GRANT ALL PRIVILEGES ON leginondb.* TO usr_object@'localhost';
157 1 Amber Herold
GRANT ALL PRIVILEGES ON projectdb.* TO usr_object@'localhost';
158
</pre>
159 24 Neil Voss
160 41 Amber Herold
You may also choose to assign a domain to your commands and use a wildcard to allow access from all computers in the domain. 
161 26 Neil Voss
162 1 Amber Herold
<pre>
163 36 Amber Herold
CREATE USER usr_object@'%.mydomain.edu' IDENTIFIED BY 'YOUR PASSWORD';
164
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON leginondb.* to usr_object@'%.mydomain.edu';
165 1 Amber Herold
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON projectdb.* to usr_object@'%.mydomain.edu';
166 24 Neil Voss
</pre>
167 3 Amber Herold
168 42 Amber Herold
h3. 11 Give create and access privileges for the processing databases which begin with "ap".
169 10 Neil Voss
170 24 Neil Voss
<pre>
171 27 Neil Voss
# if your web host is local
172 36 Amber Herold
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON `ap%`.* to usr_object@localhost; 
173 27 Neil Voss
# for all other hosts if you are accessing the databases from another computer
174 36 Amber Herold
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON `ap%`.* to usr_object@'%.mydomain.edu';       
175 1 Amber Herold
</pre>
176
177 42 Amber Herold
h3. 12 Change Root password
178 1 Amber Herold
179 28 Neil Voss
To set the root password use the command: 
180 1 Amber Herold
181 28 Neil Voss
<pre>
182
sudo mysqladmin -u root password NEWPASSWORD
183
</pre>
184 1 Amber Herold
185 28 Neil Voss
Or you can do it from within mysql
186 10 Neil Voss
<pre>
187 36 Amber Herold
update user set password=password('your_own_root_password') where user="root";
188 1 Amber Herold
Query OK, 2 rows affected (0.01 sec)
189
Rows matched: 2  Changed: 2  Warnings: 0
190
191 36 Amber Herold
flush privileges;
192
^D or exit;
193 3 Amber Herold
</pre>
194 1 Amber Herold
195 3 Amber Herold
196 1 Amber Herold
From now on, you will need to specify the password to connect to the database as root user like this:
197
198 30 Neil Voss
<pre>
199 36 Amber Herold
mysql -u root -p mysql
200 1 Amber Herold
</pre>
201
202 42 Amber Herold
h3. 13 Check MySQL variables
203 1 Amber Herold
204 31 Neil Voss
<pre>
205 36 Amber Herold
mysql -u usr_object -p leginondb
206 1 Amber Herold
207 36 Amber Herold
SHOW VARIABLES LIKE 'query%';
208 1 Amber Herold
      +------------------------------+-----------+
209
      | Variable_name                | Value     |
210
      +------------------------------+-----------+
211
      | ft_query_expansion_limit     | 20        |
212
      | have_query_cache             | YES       |
213
      | long_query_time              | 10        |
214
      | query_alloc_block_size       | 8192      |
215
      | query_cache_limit            | 104857600 | <<---This should correspond to your change
216
      | query_cache_min_res_unit     | 4096      |
217
      | query_cache_size             | 104857600 | <<---This should correspond to your change
218
      | query_cache_type             | ON        | <<---This should correspond to your change
219
      | query_cache_wlock_invalidate | OFF       |
220
      | query_prealloc_size          | 8192      |
221
      +------------------------------+-----------+
222
      10 rows in set (0.00 sec)
223
224 36 Amber Herold
exit;
225 1 Amber Herold
</pre>
226
227 42 Amber Herold
h3. 14 Make sure MySQL is running
228 1 Amber Herold
229 3 Amber Herold
<pre>
230 36 Amber Herold
mysqlshow
231 1 Amber Herold
      +--------------+
232
      | Databases    |
233 30 Neil Voss
      +--------------+
234
      | mysql        |
235
      | leginondb    |
236
      | projectdb    |
237 1 Amber Herold
      +--------------+
238
</pre>
239 30 Neil Voss
240 36 Amber Herold
h3. Run the following command from the command line:
241 1 Amber Herold
242 30 Neil Voss
<pre>
243 1 Amber Herold
php -r "mysql_connect('localhost', 'usr_object', 'PASSWORD', 'leginondb'); echo mysql_stat();"; echo ""
244
</pre>
245 30 Neil Voss
246 1 Amber Herold
Expected output:
247
248 30 Neil Voss
<pre>
249
Uptime: 1452562 Threads: 1 Questions: 618 Slow queries: 0 Opens: 117 Flush tables: 1 Open tables: 106 Queries per second avg: 0.000
250 1 Amber Herold
</pre>
251 30 Neil Voss
252 36 Amber Herold
If there are any error messages, mysql may be configured incorrectly.
253 30 Neil Voss
254 1 Amber Herold
h2. Configure phpMyAdmin 
255 30 Neil Voss
256 1 Amber Herold
Edit the phpMyAdmin config file @/etc/phpMyAdmin/config.inc.php@ and change the following lines:
257 12 Neil Voss
258 30 Neil Voss
<pre>
259 1 Amber Herold
$cfg['Servers'][$i]['AllowRoot']     = FALSE;
260
</pre>
261 30 Neil Voss
262 1 Amber Herold
Edit the phpMyAdmin apache config file @/etc/httpd/conf.d/phpMyAdmin.conf@ and change the following lines:
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 31 Neil Voss
</pre>
272
273 1 Amber Herold
*Note:* If you want to access phpMyAdmin from another computer, you can also add it to this config file with an @allow from@ tag
274 33 Neil Voss
275
Next restart the web server to take on the new setting
276
<pre>
277
sudo /sbin/service httpd restart
278
</pre>
279 1 Amber Herold
280 35 Neil Voss
To test the phpMyAdmin configuration, point your browser to http://YOUR_IP_ADDRESS/phpMyAdmin or http://localhost/phpMyAdmin and login with the usr_object user.
281
282 33 Neil Voss
!phpMyAdmin.png!
283
284
A common problem is that the firewall may be blocking access to the web server and mysql server. On CentOS/Fedora you can configure this with the system config:
285
286
<pre>
287
system-config-securitylevel
288
</pre>
289
290 1 Amber Herold
Firewall configuration is specific to different Unix distributions, so consult a guide on how to do this on non-RedHat machines.