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