Wednesday, December 28, 2011

"Using Lock tables" error while taking Mysqldump

This is the comman error which we get while taking the mysqldump of large databases.

File './databasename/tablename.MYD' not found (Errcode: 24) when using LOCK TABLES

If you will print the system error code 24 by using perror, it will return  "OS error code  24:  Too many open files"
This error can be resolve in several ways -
1- set open-files-limit=10000(or any higher number)
or define open-files-limit and open_files_limit in configuration files.

Note- if you are using MySQL version < 5.1.52. only use open-files-limit don't use open_files_limit. In these version open_files_limit can't set limit higher than 65535. But for newer version these issues are fixed.

2- By using --single-transaction with mysqldump i.e - mysqldump --single-transactions -uroot -p database>database.sql
    This option sends a START TRANSACTION SQL statement to the server before dumping data. It is useful only with transactional tables such as InnoDB and BDB, because then it dumps the consistent state of the database at the time when BEGIN was issued without blocking any applications.
    When using this option, you should keep in mind that only InnoDB tables are dumped in a consistent state. For example, any MyISAM or MEMORY tables dumped while using this option may still change state.(src -http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html)
   
3- while taking the mysql dump, use –-lock-tables=false option. But remember it is not recomended for innoDB engines

Every dumped database, lock all tables to be dumped before dumping them. These tables locked to allow  concurrent inserts in the case of MyISAM tables with READ LOCAL . In case of Innodb (transactional) tables, --single-transaction better than --lock-tables because it does not need to lock the tables.

Since this option locks tables for each database separately, it is not guaranteed that the tables in the dump file are logically consistent between databases. Tables in different databases may be dumped in completely different states

Thursday, June 30, 2011

Setting up mod_wsgi for python in the web

Mostly web servers cannot execute Python code directly. They need some kind of bridge between the program and server. The purpose of these bridges is to define how programs interact with the server.

Python Installation - 
Python Installation from Source -
1- Download python source from 
http://www.python.org/getit/
2- tar xfz Python-3.1.tgz
3-cd Python-3.1
4-make
5-make install

Python Installation on Windows -
1- Download python installer from 
http://www.python.org/getit
2- Double click the installer
3- Follow the steps of installer
4- Once you have done, just check Start>>Programs>>Python 3.1>>IDLE (Python GUI). You will see the Python IDE

Now Download mod_wsgi from -
http://code.google.com/p/modwsgi/downloads/list
Just check your Python and Apache version and download according to that.
From Source code follow this step -
Unpack the mod_wsgi and run the usual:
1 - untar it
2 ./configure
3 make
4 sudo make install
 If you have downloaded binary Apache Module for Win32, rename to - mod_wsgi.
5 Copy it in apache modules directory. In my case it was -
C:\xampp\apache\modules  
6 Add the following line to your httpd.conf ( C:\xampp\apache\conf\httpd.conf)
   LoadModule wsgi_module modules/mod_wsgi.so
7 Now restart Apache.

Write a WSGI Python code my.py and put into you htdocs/myapp-
def application(env, start_response):
    start_response("200 OK", [])
    output = "Hello World! Request: %s"
    output %= env['PATH_INFO']
    return [output]

Now add following lines to httpd.conf. 
WSGIScriptAlias /myapp "C:/xampp/htdocs/myapp/"

    Order deny,allow
    Allow from all


Modify mime.types by adding 'py' -

text/html        html htm py

Now restart the apache and try this in your browser -http://localhost/myapp/my.py