Uploading a mysql database to a webserver supporting python
I have a written a very small web-based survey using cgi with python(This is my first web app. ).The questions are extracted from a MySQL database table and the results are supposed to be saved in the same database. I have created the database along with its table locally. My app works fine on my local computer(localhost). To create db,table and other transaction with the MySQL i had to do import MySQLdb
in my code.
Now I want to upload everything on my personal hosting. As far as I know my hosting supports Python,CGI and has MySQL database. And I know that I have to change some parameters in the connection string in my code, so I can connect to the database, but I have two problems:
- 开发者_运维知识库I remember that I installed
MySQLdb
as an extra to my Python, and in my code i am using it, how would I know that my hosting's python interpretor has this installed, or do I even need it, do I have to use another library? - How do I upload my database onto my hosting? Thanks
If you have shell access, you can fire up the python interpreter by running
python
and typeimport MySQLdb
at the>>>
prompt. If you get no errors in return, then its installed.Likewise, if you have shell access, this page will help you with importing and exporting using the mysql command. I found it by googleing "import export mysql".
- You can write a simple script like import MySQLdb and catch any errors to see if the required package is installed. If this fails you can ask the hosting provider to install your package, typically via a ticket
- The hosting providers typically also provide URL's to connect to the MySQL tables they provision for you, and some tools like phpmyadmin to load database dumps into the hosted MySQL instance
To check if MySQLdb library is installed on your hosting, simply open a python shell and type: import MySQLdb
. If everthing goes ok, you're readt to go. If you get: ImportError: No module named MySQLdb
, that means the the library is not installed and you nedd to install it.
You need that library or some library that provides similar support, because Python does not support native access to MySQL databases.
To transfer you database to your hosting check mysqldump.
精彩评论