wiki:InstallationGuidelines/MySQL

Version 15 (modified by Fran Boon, 14 years ago) ( diff )

--

Installation on MySQL

Replacing the simple SQLite database with MySQL allows greater scalability

Notes

  1. The databases directory contains what web2py knows about your database
  2. You need to set deployment_settings.base.migrate=True in models/000_config.py before you update the code and switch back to deployment_settings.base.migrate=False later on.
  3. In case of database mismatches - check the databases directory for the appropriate .table file and change accordingly.

Install MySQL

apt-get install mysql-server

Install phpMyAdmin

optional, but highly recommended for easier GUI-based administration

apt-get install phpmyadmin

Install Python support for MySQL

apt-get install python-mysqldb

or

wget http://downloads.sourceforge.net/project/mysql-python/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz
tar zxvf MySQL-python-1.2.3c1.tar.gz
cd MySQL-python-1.2.3c1
python setup.py install

Create the database

Database should be created within MySQL before Web2Py can see it to add the relevant tables:

mysql -u root -p
 CREATE DATABASE sahana;
 GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,ALTER ON sahana.* TO 'sahana'@'localhost' IDENTIFIED BY 'mypassword';
 FLUSH PRIVILEGES;

Configure Eden

Connection pools allow connections to be reused.

The number used is defined in models/000_config.py

How many pools?

Whatever you choose, it always starts with one and grows with the number of concurrent requests up to the value of pools (the max number of concurrent pools). So pools should be the max number of concurrent requests you expect. That is the max value of:

<number of requests/second> / <average time per request in seconds>

MySQL optimisation

For Production instances, give the MySQL database plenty of RAM:

innodb_buffer_pool_size = 2048M
innodb_file_per_table
innodb_thread_concurrency = 8

MySQL Replication

In order to have a backup instance, configure replication from the Master node to a Backup node:

On Master:

pico /etc/mysql/my.cnf
#bind-address = 127.0.0.1
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = sahana

/etc/init.d/mysql restart

mysql -u root -p
GRANT REPLICATION SLAVE ON sahana.* to username@'sl.av.e.ip' IDENTIFIED BY 'mypassword';
FLUSH PRIVILEGES;
SHOW MASTER STATUS;

Read log filename & position for configuring the slave (see below).

On Slave:

pico /etc/mysql/my.cnf
server-id = 2
master-host = ma.st.er.ip
master-user = username
master-password = mypassword
master-connect-retry = 60
replicate-do-db = sahana

/etc/init.d/mysql restart

mysql -u root -p

SLAVE STOP;
CHANGE MASTER TO MASTER_HOST='ma.st.er.ip', MASTER_USER='username', MASTER_PASSWORD='mypassword', MASTER_LOG_FILE='log_file', MASTER_LOG_POS=log_position;
SLAVE START;

crontab -e 
# m h  dom mon dow   command
55 * * * * /home/instance/scripts/automysqlbackup
55 * * * * /home/instance/scripts/sync-dir

IP Failover

Can configure the slave to adopt the same IP as the master using a Heartbeat:

If using Slicehost:


InstallationGuidelines

DeveloperGuidelinesDataMigration

Note: See TracWiki for help on using the wiki.