Database Server Installation Shared » History » Version 10
Neil Voss, 05/12/2010 08:17 AM
1 | 1 | Amber Herold | h1. Database Server Installation |
---|---|---|---|
2 | |||
3 | |||
4 | h2. Install MySQL |
||
5 | |||
6 | The following is for the computer that hosts the databases. This involves installing MySQL server and creation/configuration of the leginondb and projectdb databases. |
||
7 | |||
8 | Note: You may already have MySQL Server and Client installed. Check by typing mysql at the command line. |
||
9 | If you see a MySQL prompt (mysql>), skip steps 1 and 2. |
||
10 | |||
11 | h3. 1. Install MySQL-Server |
||
12 | |||
13 | * Use your package installer (yum, zypper, YaST) if available. |
||
14 | OR |
||
15 | * Download the latest MySQL-server RPM for Linux from www.mysql.com |
||
16 | * Install the MySQL-server rpm: |
||
17 | |||
18 | rpm -Uvh MySQL-server-5.0.xx-y.i386.rpm |
||
19 | |||
20 | (substitute correct version numbers) |
||
21 | |||
22 | h3. 2. Install MySQL-Client |
||
23 | |||
24 | * Use your package installer (yum, zypper, YaST) if available. |
||
25 | OR |
||
26 | * Download the latest MySQL-client RPM for Linux from www.mysql.com |
||
27 | * Install the MySQL-client rpm: |
||
28 | |||
29 | rpm -Uvh MySQL-client-5.0.xx-y.i386.rpm |
||
30 | |||
31 | (substitute correct version numbers) |
||
32 | |||
33 | h3. 3. MySQL configuration file is usually located in /usr/share/mysql. There are several examples there: |
||
34 | |||
35 | 3 | Amber Herold | <pre> |
36 | 10 | Neil Voss | ls /usr/share/mysql/my* |
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 | 9 | Anchi Cheng | <pre> |
53 | query_cache_type= 1 |
||
54 | 1 | Amber Herold | query_cache_size = 100M |
55 | 9 | Anchi Cheng | query_cache_limit= 100M |
56 | </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 | 9 | Anchi Cheng | default-storage-engine=MyISAM |
61 | </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 | 1 | Amber Herold | on some installation, |
78 | |||
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 | 3 | Amber Herold | If you want to start MySQL automatically at boot on SuSE |
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 | <pre> |
||
103 | 10 | Neil Voss | ls /var/lib/mysql |
104 | |||
105 | ibdata1 ib_logfile0 ib_logfile1 mysql mysql.sock test |
||
106 | 1 | Amber Herold | </pre> |
107 | |||
108 | h3. 7. Create the Leginon database, call it leginondb |
||
109 | 3 | Amber Herold | |
110 | 1 | Amber Herold | <pre> |
111 | 10 | Neil Voss | sudo mysqladmin create leginondb |
112 | 1 | Amber Herold | </pre> |
113 | |||
114 | h3. 8. Create the Project database, call it projectdb |
||
115 | |||
116 | <pre> |
||
117 | 10 | Neil Voss | sudo mysqladmin create projectdb |
118 | 1 | Amber Herold | </pre> |
119 | |||
120 | h3. 9. Connect to mysql db |
||
121 | |||
122 | <pre> |
||
123 | >mysql mysql |
||
124 | |||
125 | mysql> select user, password, host from user; |
||
126 | +------+----------+-----------+ |
||
127 | | user | password | host | |
||
128 | +------+----------+-----------+ |
||
129 | | root | | localhost | |
||
130 | | root | | host1 | |
||
131 | | | | host1 | |
||
132 | | | | localhost | |
||
133 | +------+----------+-----------+ |
||
134 | 4 rows in set (0.00 sec) |
||
135 | </pre> |
||
136 | |||
137 | h3. 10. Create user |
||
138 | |||
139 | 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 may also set specific privilege to the user. See MySQL Reference Manual for details |
||
140 | 3 | Amber Herold | |
141 | 1 | Amber Herold | <pre> |
142 | 10 | Neil Voss | mysql> create user usr_object@'localhost'; |
143 | mysql> grant all privileges on leginondb.* to usr_object@'localhost'; |
||
144 | mysql> grant all privileges on projectdb.* to usr_object@'localhost'; |
||
145 | 1 | Amber Herold | </pre> |
146 | |||
147 | Similarly, |
||
148 | 3 | Amber Herold | |
149 | 1 | Amber Herold | <pre> |
150 | 10 | Neil Voss | mysql> create user usr_object@'%'; |
151 | mysql> grant all privileges on leginondb.* to usr_object@<host.mydomain.edu>; |
||
152 | mysql> grant all privileges on projectdb.* to usr_object@<host.mydomain.edu>; |
||
153 | 1 | Amber Herold | </pre> |
154 | |||
155 | Next, give create and access privileges for the processing databases which begin with "ap". |
||
156 | 3 | Amber Herold | |
157 | 1 | Amber Herold | <pre> |
158 | 10 | Neil Voss | // if your web host is local |
159 | mysql> grant all privileges on `ap%`.* to usr_object@localhost; |
||
160 | // for all other hosts if you are accessing the databases from another computer |
||
161 | mysql> grant all privileges on `ap%`.* to usr_object@<host.mydomain.edu>; |
||
162 | 1 | Amber Herold | </pre> |
163 | |||
164 | h3. 11. Change Root password |
||
165 | |||
166 | 10 | Neil Voss | <pre><code class="ruby"> |
167 | 1 | Amber Herold | |
168 | 10 | Neil Voss | mysql> update user set password=password('your_own_root_password') where user="root"; |
169 | Query OK, 2 rows affected (0.01 sec) |
||
170 | Rows matched: 2 Changed: 2 Warnings: 0 |
||
171 | |||
172 | mysql> flush privileges; |
||
173 | mysql>^D or exit; |
||
174 | </code></pre> |
||
175 | |||
176 | 3 | Amber Herold | |
177 | 1 | Amber Herold | From now on, you will need to specify the password to connect to the database as root user like this: |
178 | 3 | Amber Herold | |
179 | 1 | Amber Herold | <pre> |
180 | >mysql -u root -p mysql |
||
181 | </pre> |
||
182 | |||
183 | h3. 12. Check MySQL variables |
||
184 | |||
185 | <pre> |
||
186 | >mysql -u usr_object leginondb |
||
187 | |||
188 | mysql> SHOW VARIABLES LIKE 'query%'; |
||
189 | +------------------------------+-----------+ |
||
190 | | Variable_name | Value | |
||
191 | +------------------------------+-----------+ |
||
192 | | ft_query_expansion_limit | 20 | |
||
193 | | have_query_cache | YES | |
||
194 | | long_query_time | 10 | |
||
195 | | query_alloc_block_size | 8192 | |
||
196 | | query_cache_limit | 104857600 | <<---This should correspond to your change |
||
197 | | query_cache_min_res_unit | 4096 | |
||
198 | | query_cache_size | 104857600 | <<---This should correspond to your change |
||
199 | | query_cache_type | ON | <<---This should correspond to your change |
||
200 | | query_cache_wlock_invalidate | OFF | |
||
201 | | query_prealloc_size | 8192 | |
||
202 | +------------------------------+-----------+ |
||
203 | 10 rows in set (0.00 sec) |
||
204 | |||
205 | mysql> exit; |
||
206 | </pre> |
||
207 | |||
208 | h3. 13. Make sure MySQL is running |
||
209 | |||
210 | <pre> |
||
211 | prompt:~> mysqlshow |
||
212 | +--------------+ |
||
213 | | Databases | |
||
214 | +--------------+ |
||
215 | | mysql | |
||
216 | | leginondb | |
||
217 | | projectdb | |
||
218 | +--------------+ |
||
219 | </pre> |
||
220 | 3 | Amber Herold | |
221 | 1 | Amber Herold | h3. 14. Or check with the following php script (if already installed) |
222 | |||
223 | <pre> |
||
224 | <? |
||
225 | 3 | Amber Herold | mysql_connect('your_host.your_institute.edu', 'usr_object', '','leginondb'); |
226 | 1 | Amber Herold | echo mysql_stat(); |
227 | 3 | Amber Herold | ?> |
228 | 1 | Amber Herold | </pre> |
229 | 3 | Amber Herold | |
230 | 1 | Amber Herold | Output: |
231 | 3 | Amber Herold | |
232 | 1 | Amber Herold | <pre> |
233 | Uptime: 1452562 Threads: 1 Questions: 618 Slow queries: 0 Opens: 117 Flush tables: 1 Open tables: 106 Queries per second avg: 0.000 |
||
234 | </pre> |
||
235 | |||
236 | h2. Configure phpMyAdmin |
||
237 | |||
238 | Edit the phpMyAdmin config file: |
||
239 | |||
240 | <pre> |
||
241 | $ sudo vi /etc/phpMyAdmin/config.inc.php |
||
242 | </pre> |
||
243 | |||
244 | and change the following lines: |
||
245 | |||
246 | <pre> |
||
247 | $cfg['Servers'][$i]['AllowRoot'] = FALSE; |
||
248 | </pre> |
||
249 | |||
250 | Edit the phpMyAdmin apache config file: |
||
251 | |||
252 | <pre> |
||
253 | $ sudo vi /etc/httpd/conf.d/phpMyAdmin.conf |
||
254 | </pre> |
||
255 | |||
256 | and change the following lines: |
||
257 | |||
258 | *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 |
||
259 | |||
260 | <pre> |
||
261 | <Directory /usr/share/phpMyAdmin/> |
||
262 | order deny,allow |
||
263 | deny from all |
||
264 | allow from 127.0.0.1 |
||
265 | allow from YOUR_IP_ADDRESS |
||
266 | </Directory> |
||
267 | </pre> |
||
268 | |||
269 | To test the PHPMyAdmin configuration, point your browser to http://YOUR_IP_ADDRESS/phpmyadmin. |