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