
Greetings to you friend, this evening I decided to make this post for two reasons, one of which is that I haven't actually written any posts on this blog for a while now and secondly, they say if you learn something new and want it to assimilate, you blog it.
<warning>
This post is strongly recommended for those who have knowledge in python programming and flask micro web framework, as it is not very much detailed.
I know a lot of young python programmers who started learning flask and have probably ended up with issues like the following:
How do I use an online MySql with Flask?
How do I use a different Database such as MySql?
How do I use an SqlAlchemy with MySql?
etc.
Well, my dear reader I'm a young programmer like you and I have run it issues like that too, but I'll show you something I learned, which I think might help you.
Enough of the Talkie Talkie lets do the walkie walkie, just follow me religiously and if you have any questions you can use the comment section.
First, you should have flask and flask SqlAlchemy already installed
Next, you need to activate your virtual environment
If you're on a Unix system you type this:
source ven/bin/activate
If you're on window you type this:
venv\Scripts\activate
Now, you need to go ahead and signup for an online Mysql database using any free database websites of your choice, i.e if you can't afford the paid one.
In order to follow along with me I suggest you signup with db4free and you can have access to a phpmyadmin which allows you to create a MySql database on the server.
Thereafter, you need to set the SQLALCHEMY_DATABASE_URI like this
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://scott:tiger@localhost/mydatabase'
There's a few things you have to change in the URI string. Which includes:
1) scott - should be the username you used on db4free.net
2) tiger - should be the password
3) localhost - should be the host for db4free which is this 85.10.205.173
4) mydatabase - should be the database you created on db4free
If you have done this successfully, then you can go ahead and query the database within your terminal and you should find your data within it.
Please this is post doesn't give a detailed explanation about a lot of things, but if you have any questions I'll be right here to attend to that, but for the mean time, thank you very much for stopping by.
0 comments:
Post a Comment