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