Category: mysql

Python Mysql connection and extracting sample data

In this tutorial we are going to learn how to connect to MYSQL using python.

DB Configuration:

First of all we need a config.py that will act as a configuration file that our python script will read. This configuration file consists information of MYSQL database username and password, database name and host where the MYSQL is at.

This is how config.py will look like

server = dict(
    #serverip = 'localhost',
    dbhost = 'localhost',
    dbname = 'userdb',
    dbuser = 'root',
    dbpassword = 'root123'
)

Then the actual python script that will connect using these parameters to our db and fetch results as needed.

Handling error “You probably tried to upload a file that is too large. Please refer to documentation for a workaround for this limit.”

Handling error “You probably tried to upload a file that is too large. Please refer to documentation for a workaround for this limit.”Usually, we come across such errors when we try to import a large file in to MySQL through phpmyadmin. This is because there is a pre-defined file limit in PHP for file upload which is 2MB.You may change the file upload limit as per your requirement by changing php configuration following the below steps :1. Navigate to apache2 directory and open php.ini file using vi or vim editor.

root@user-B85M-D3H:~# vim /etc/php5/apache2/php.ini 

2. Change the values of the following lines to as per your requirement.(I am changing the limit to 120 MB here)

 upload_max_filesize 120M //file size
 post_max_size 120M
 max_execution_time 200
 max_input_time 200

3. Please ensure that the max_execution_time, max_input_time should always be greater than upload_max_filesize and post_max_size.

4. Once you make the changes, save the file and restart the apache server using the command :

service apache2 restart 

Hope this helps. Happy coding!