Project

General

Profile

Database Server Installation Shared » History » Version 43

Amber Herold, 05/17/2010 12:30 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 43 Amber Herold
# run the flush privileges command to avoid problems
192 36 Amber Herold
flush privileges;
193
^D or exit;
194 3 Amber Herold
</pre>
195 1 Amber Herold
196 3 Amber Herold
197 1 Amber Herold
From now on, you will need to specify the password to connect to the database as root user like this:
198
199 30 Neil Voss
<pre>
200 36 Amber Herold
mysql -u root -p mysql
201 1 Amber Herold
</pre>
202
203 42 Amber Herold
h3. 13 Check MySQL variables
204 1 Amber Herold
205 31 Neil Voss
<pre>
206 36 Amber Herold
mysql -u usr_object -p leginondb
207 1 Amber Herold
208 36 Amber Herold
SHOW VARIABLES LIKE 'query%';
209 1 Amber Herold
      +------------------------------+-----------+
210
      | Variable_name                | Value     |
211
      +------------------------------+-----------+
212
      | ft_query_expansion_limit     | 20        |
213
      | have_query_cache             | YES       |
214
      | long_query_time              | 10        |
215
      | query_alloc_block_size       | 8192      |
216
      | query_cache_limit            | 104857600 | <<---This should correspond to your change
217
      | query_cache_min_res_unit     | 4096      |
218
      | query_cache_size             | 104857600 | <<---This should correspond to your change
219
      | query_cache_type             | ON        | <<---This should correspond to your change
220
      | query_cache_wlock_invalidate | OFF       |
221
      | query_prealloc_size          | 8192      |
222
      +------------------------------+-----------+
223
      10 rows in set (0.00 sec)
224
225 36 Amber Herold
exit;
226 1 Amber Herold
</pre>
227
228 42 Amber Herold
h3. 14 Make sure MySQL is running
229 1 Amber Herold
230 3 Amber Herold
<pre>
231 36 Amber Herold
mysqlshow
232 1 Amber Herold
      +--------------+
233
      | Databases    |
234 30 Neil Voss
      +--------------+
235
      | mysql        |
236
      | leginondb    |
237
      | projectdb    |
238 1 Amber Herold
      +--------------+
239
</pre>
240 30 Neil Voss
241 36 Amber Herold
h3. Run the following command from the command line:
242 1 Amber Herold
243 30 Neil Voss
<pre>
244 1 Amber Herold
php -r "mysql_connect('localhost', 'usr_object', 'PASSWORD', 'leginondb'); echo mysql_stat();"; echo ""
245
</pre>
246 30 Neil Voss
247 1 Amber Herold
Expected output:
248
249 30 Neil Voss
<pre>
250
Uptime: 1452562 Threads: 1 Questions: 618 Slow queries: 0 Opens: 117 Flush tables: 1 Open tables: 106 Queries per second avg: 0.000
251 1 Amber Herold
</pre>
252 30 Neil Voss
253 36 Amber Herold
If there are any error messages, mysql may be configured incorrectly.
254 30 Neil Voss
255 1 Amber Herold
h2. Configure phpMyAdmin 
256 30 Neil Voss
257 1 Amber Herold
Edit the phpMyAdmin config file @/etc/phpMyAdmin/config.inc.php@ and change the following lines:
258 12 Neil Voss
259 30 Neil Voss
<pre>
260 1 Amber Herold
$cfg['Servers'][$i]['AllowRoot']     = FALSE;
261
</pre>
262 30 Neil Voss
263 1 Amber Herold
Edit the phpMyAdmin apache config file @/etc/httpd/conf.d/phpMyAdmin.conf@ and change the following lines:
264
265
<pre>
266
<Directory /usr/share/phpMyAdmin/>
267
   order deny,allow
268
   deny from all
269
   allow from 127.0.0.1
270
   allow from YOUR_IP_ADDRESS
271
</Directory>
272 31 Neil Voss
</pre>
273
274 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
275 33 Neil Voss
276
Next restart the web server to take on the new setting
277
<pre>
278
sudo /sbin/service httpd restart
279
</pre>
280 1 Amber Herold
281 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.
282
283 33 Neil Voss
!phpMyAdmin.png!
284
285
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:
286
287
<pre>
288
system-config-securitylevel
289
</pre>
290
291 1 Amber Herold
Firewall configuration is specific to different Unix distributions, so consult a guide on how to do this on non-RedHat machines.