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