Database Server Installation Shared » History » Version 41
Amber Herold, 05/17/2010 12:14 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 | h3. 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 | 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 | 20 | Neil Voss | </pre> |
| 30 | If that does not work try the locate function |
||
| 31 | <pre> |
||
| 32 | 15 | Neil Voss | locate my | egrep "\.cnf$" |
| 33 | /etc/my.cnf |
||
| 34 | 1 | Amber Herold | /usr/share/mysql/my-huge.cnf |
| 35 | /usr/share/mysql/my-innodb-heavy-4G.cnf |
||
| 36 | /usr/share/mysql/my-large.cnf |
||
| 37 | /usr/share/mysql/my-medium.cnf |
||
| 38 | /usr/share/mysql/my-small.cnf |
||
| 39 | 3 | Amber Herold | </pre> |
| 40 | 1 | Amber Herold | |
| 41 | 15 | Neil Voss | h3. Configure my.cnf in /etc using my-huge.cnf as the template |
| 42 | 1 | Amber Herold | |
| 43 | 18 | Neil Voss | # Copy my-huge.cnf to my.cnf |
| 44 | 19 | Neil Voss | <pre>sudo cp -v /usr/share/mysql/my-huge.cnf /etc/my.cnf</pre> |
| 45 | 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): |
| 46 | 1 | Amber Herold | <pre> |
| 47 | 39 | Amber Herold | query_cache_type = 1 |
| 48 | 1 | Amber Herold | query_cache_size = 100M |
| 49 | query_cache_limit= 100M |
||
| 50 | 21 | Neil Voss | </pre> |
| 51 | 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: |
| 52 | 1 | Amber Herold | <pre>default-storage-engine=MyISAM</pre> |
| 53 | 10 | Neil Voss | |
| 54 | 22 | Neil Voss | h3. Start the MySQL Server |
| 55 | 1 | Amber Herold | |
| 56 | 10 | Neil Voss | For CentOS/Fedora/RHEL system use the service command: |
| 57 | |||
| 58 | 1 | Amber Herold | <pre> |
| 59 | 10 | Neil Voss | sudo /sbin/service mysqld start |
| 60 | 1 | Amber Herold | </pre> |
| 61 | |||
| 62 | 10 | Neil Voss | For other Unix systems: |
| 63 | |||
| 64 | <pre> |
||
| 65 | sudo /etc/init.d/mysqld start |
||
| 66 | </pre> |
||
| 67 | |||
| 68 | 12 | Neil Voss | or on some installations, |
| 69 | 1 | Amber Herold | |
| 70 | <pre> |
||
| 71 | 10 | Neil Voss | sudo /etc/init.d/mysql start |
| 72 | 1 | Amber Herold | </pre> |
| 73 | |||
| 74 | For future reference: start | stop | restart MySQL Server with similar commands: |
||
| 75 | |||
| 76 | <pre> |
||
| 77 | 10 | Neil Voss | sudo /etc/init.d/mysqld start |
| 78 | sudo /etc/init.d/mysqld stop |
||
| 79 | sudo /etc/init.d/mysqld restart |
||
| 80 | sudo /sbin/service mysqld start |
||
| 81 | sudo /sbin/service mysqld stop |
||
| 82 | sudo /sbin/service mysqld restart |
||
| 83 | 1 | Amber Herold | </pre> |
| 84 | |||
| 85 | 12 | Neil Voss | If you want to start MySQL automatically at boot |
| 86 | 1 | Amber Herold | |
| 87 | <pre> |
||
| 88 | 37 | Amber Herold | sudo /sbin/chkconfig mysqld on |
| 89 | 1 | Amber Herold | </pre> |
| 90 | 23 | Neil Voss | or for SuSe: |
| 91 | <pre> |
||
| 92 | sudo /sbin/chkconfig mysql on |
||
| 93 | </pre> |
||
| 94 | 1 | Amber Herold | |
| 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 | 11 | Neil Voss | h3. 9. Connect to mysql db |
| 115 | |||
| 116 | 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. |
| 117 | 1 | Amber Herold | |
| 118 | 23 | Neil Voss | <pre> |
| 119 | 28 | Neil Voss | mysql -u root mysql |
| 120 | 23 | Neil Voss | </pre> |
| 121 | 1 | Amber Herold | |
| 122 | 40 | Amber Herold | You should see a mysql prompt: mysql> |
| 123 | |||
| 124 | You can view the current mysql users with the following command. |
||
| 125 | 11 | Neil Voss | <pre> |
| 126 | 40 | Amber Herold | select user, password, host from user; |
| 127 | 1 | Amber Herold | +------+----------+-----------+ |
| 128 | | user | password | host | |
||
| 129 | +------+----------+-----------+ |
||
| 130 | | root | | localhost | |
||
| 131 | | root | | host1 | |
||
| 132 | | | | host1 | |
||
| 133 | | | | localhost | |
||
| 134 | +------+----------+-----------+ |
||
| 135 | 4 rows in set (0.00 sec) |
||
| 136 | </pre> |
||
| 137 | |||
| 138 | h3. 10. Create user |
||
| 139 | |||
| 140 | 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. |
| 141 | 3 | Amber Herold | |
| 142 | 36 | Amber Herold | At the mysql prompt execute the following commands: |
| 143 | 1 | Amber Herold | <pre> |
| 144 | 36 | Amber Herold | CREATE USER usr_object@'localhost' IDENTIFIED BY 'YOUR PASSWORD'; |
| 145 | GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON leginondb.* TO usr_object@'localhost'; |
||
| 146 | GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON projectdb.* TO usr_object@'localhost'; |
||
| 147 | 1 | Amber Herold | </pre> |
| 148 | |||
| 149 | 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. |
| 150 | 1 | Amber Herold | |
| 151 | 36 | Amber Herold | At the mysql prompt execute the following commands: |
| 152 | 24 | Neil Voss | <pre> |
| 153 | 36 | Amber Herold | CREATE USER usr_object@'localhost'; |
| 154 | GRANT ALL PRIVILEGES ON leginondb.* TO usr_object@'localhost'; |
||
| 155 | GRANT ALL PRIVILEGES ON projectdb.* TO usr_object@'localhost'; |
||
| 156 | 1 | Amber Herold | </pre> |
| 157 | 24 | Neil Voss | |
| 158 | 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. |
| 159 | 26 | Neil Voss | |
| 160 | 1 | Amber Herold | <pre> |
| 161 | 36 | Amber Herold | CREATE USER usr_object@'%.mydomain.edu' IDENTIFIED BY 'YOUR PASSWORD'; |
| 162 | GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON leginondb.* to usr_object@'%.mydomain.edu'; |
||
| 163 | GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON projectdb.* to usr_object@'%.mydomain.edu'; |
||
| 164 | 24 | Neil Voss | </pre> |
| 165 | 3 | Amber Herold | |
| 166 | 41 | Amber Herold | h3. Give create and access privileges for the processing databases which begin with "ap". |
| 167 | 10 | Neil Voss | |
| 168 | 24 | Neil Voss | <pre> |
| 169 | 27 | Neil Voss | # if your web host is local |
| 170 | 36 | Amber Herold | GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON `ap%`.* to usr_object@localhost; |
| 171 | 27 | Neil Voss | # for all other hosts if you are accessing the databases from another computer |
| 172 | 36 | Amber Herold | GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON `ap%`.* to usr_object@'%.mydomain.edu'; |
| 173 | 1 | Amber Herold | </pre> |
| 174 | |||
| 175 | h3. 11. Change Root password |
||
| 176 | |||
| 177 | 28 | Neil Voss | To set the root password use the command: |
| 178 | 1 | Amber Herold | |
| 179 | 28 | Neil Voss | <pre> |
| 180 | sudo mysqladmin -u root password NEWPASSWORD |
||
| 181 | </pre> |
||
| 182 | 1 | Amber Herold | |
| 183 | 28 | Neil Voss | Or you can do it from within mysql |
| 184 | 10 | Neil Voss | <pre> |
| 185 | 36 | Amber Herold | update user set password=password('your_own_root_password') where user="root"; |
| 186 | 10 | Neil Voss | Query OK, 2 rows affected (0.01 sec) |
| 187 | 1 | Amber Herold | Rows matched: 2 Changed: 2 Warnings: 0 |
| 188 | |||
| 189 | 36 | Amber Herold | flush privileges; |
| 190 | ^D or exit; |
||
| 191 | 3 | Amber Herold | </pre> |
| 192 | 1 | Amber Herold | |
| 193 | 3 | Amber Herold | |
| 194 | 1 | Amber Herold | From now on, you will need to specify the password to connect to the database as root user like this: |
| 195 | |||
| 196 | 30 | Neil Voss | <pre> |
| 197 | 36 | Amber Herold | mysql -u root -p mysql |
| 198 | 1 | Amber Herold | </pre> |
| 199 | |||
| 200 | h3. 12. Check MySQL variables |
||
| 201 | |||
| 202 | 31 | Neil Voss | <pre> |
| 203 | 36 | Amber Herold | mysql -u usr_object -p leginondb |
| 204 | 1 | Amber Herold | |
| 205 | 36 | Amber Herold | SHOW VARIABLES LIKE 'query%'; |
| 206 | 1 | Amber Herold | +------------------------------+-----------+ |
| 207 | | Variable_name | Value | |
||
| 208 | +------------------------------+-----------+ |
||
| 209 | | ft_query_expansion_limit | 20 | |
||
| 210 | | have_query_cache | YES | |
||
| 211 | | long_query_time | 10 | |
||
| 212 | | query_alloc_block_size | 8192 | |
||
| 213 | | query_cache_limit | 104857600 | <<---This should correspond to your change |
||
| 214 | | query_cache_min_res_unit | 4096 | |
||
| 215 | | query_cache_size | 104857600 | <<---This should correspond to your change |
||
| 216 | | query_cache_type | ON | <<---This should correspond to your change |
||
| 217 | | query_cache_wlock_invalidate | OFF | |
||
| 218 | | query_prealloc_size | 8192 | |
||
| 219 | +------------------------------+-----------+ |
||
| 220 | 10 rows in set (0.00 sec) |
||
| 221 | |||
| 222 | 36 | Amber Herold | exit; |
| 223 | 1 | Amber Herold | </pre> |
| 224 | |||
| 225 | h3. Make sure MySQL is running |
||
| 226 | |||
| 227 | 3 | Amber Herold | <pre> |
| 228 | 36 | Amber Herold | mysqlshow |
| 229 | 1 | Amber Herold | +--------------+ |
| 230 | | Databases | |
||
| 231 | 30 | Neil Voss | +--------------+ |
| 232 | | mysql | |
||
| 233 | | leginondb | |
||
| 234 | | projectdb | |
||
| 235 | 1 | Amber Herold | +--------------+ |
| 236 | </pre> |
||
| 237 | 30 | Neil Voss | |
| 238 | 36 | Amber Herold | h3. Run the following command from the command line: |
| 239 | 1 | Amber Herold | |
| 240 | 30 | Neil Voss | <pre> |
| 241 | 1 | Amber Herold | php -r "mysql_connect('localhost', 'usr_object', 'PASSWORD', 'leginondb'); echo mysql_stat();"; echo "" |
| 242 | </pre> |
||
| 243 | 30 | Neil Voss | |
| 244 | 1 | Amber Herold | Expected output: |
| 245 | |||
| 246 | 30 | Neil Voss | <pre> |
| 247 | Uptime: 1452562 Threads: 1 Questions: 618 Slow queries: 0 Opens: 117 Flush tables: 1 Open tables: 106 Queries per second avg: 0.000 |
||
| 248 | 1 | Amber Herold | </pre> |
| 249 | 30 | Neil Voss | |
| 250 | 36 | Amber Herold | If there are any error messages, mysql may be configured incorrectly. |
| 251 | 30 | Neil Voss | |
| 252 | 1 | Amber Herold | h2. Configure phpMyAdmin |
| 253 | 30 | Neil Voss | |
| 254 | 1 | Amber Herold | Edit the phpMyAdmin config file @/etc/phpMyAdmin/config.inc.php@ and change the following lines: |
| 255 | 12 | Neil Voss | |
| 256 | 30 | Neil Voss | <pre> |
| 257 | 1 | Amber Herold | $cfg['Servers'][$i]['AllowRoot'] = FALSE; |
| 258 | </pre> |
||
| 259 | 30 | Neil Voss | |
| 260 | 1 | Amber Herold | Edit the phpMyAdmin apache config file @/etc/httpd/conf.d/phpMyAdmin.conf@ and change the following lines: |
| 261 | |||
| 262 | <pre> |
||
| 263 | <Directory /usr/share/phpMyAdmin/> |
||
| 264 | order deny,allow |
||
| 265 | deny from all |
||
| 266 | allow from 127.0.0.1 |
||
| 267 | allow from YOUR_IP_ADDRESS |
||
| 268 | </Directory> |
||
| 269 | 31 | Neil Voss | </pre> |
| 270 | |||
| 271 | 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 |
| 272 | 33 | Neil Voss | |
| 273 | Next restart the web server to take on the new setting |
||
| 274 | <pre> |
||
| 275 | sudo /sbin/service httpd restart |
||
| 276 | </pre> |
||
| 277 | 1 | Amber Herold | |
| 278 | 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. |
| 279 | |||
| 280 | 33 | Neil Voss | !phpMyAdmin.png! |
| 281 | |||
| 282 | 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: |
||
| 283 | |||
| 284 | <pre> |
||
| 285 | system-config-securitylevel |
||
| 286 | </pre> |
||
| 287 | |||
| 288 | 1 | Amber Herold | Firewall configuration is specific to different Unix distributions, so consult a guide on how to do this on non-RedHat machines. |