Это видео недоступно.
Сожалеем об этом.
How To Use MySQL Database With Flask - Flask Fridays #9
HTML-код
- Опубликовано: 16 авг 2024
- In this video I'll show you how to use the MYSQL database with Flask and SQLAlchemy.
In the last video we set up SQLite as the database using SQLAlchemy, in this video I'll show you how to convert that to MYSQL. It's really really easy! None of our actual code will change, we just need to point to a MYSQL database and set it up.
Timecodes
0:00 - Introduction
1:27 - Download and Install MySQL
3:44 - Set the DATABASE_URI for MySQL
6:36 - Pip Install MySQL Connectors
7:43 - Create The User Database
12:08 - Try Import Import Database From Python Shell
13:11 - Pip Install PyMySQL and cryptography
13:42 - Update MySQL DATABASE_URI For PyMySQL
14:05 - Import and Create Database From Python Shell
14:28 - Test Out the App
16:58 - Conclusion
#codemy #flask #johnelder
▶️ Watch Entire Flask Friday Playlist ✅ Subscribe To My RUclips Channel:
bit.ly/3ig2eJn bit.ly/2IGzvOR
▶️ See More At: ✅ Join My Facebook Group:
Codemy.com bit.ly/2GFmOBz
▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt!
Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN
▶️ Get The Code
bit.ly/2L1jBl5
Sqlite is absolutely a production level database! However says otherwise doesn't understand the purpose of it. Sqlite answers the question "how do we increase the speed of the `fopen()` process". In other words, if you are constantly reading data instead of writing or transactioning, Sqlite is the answer. Nevertheless, if you try to use Sqlite as a transactional database then yes of course it's not production level. Right tool for the right job.
Your videos are the best, John. One day, I hope this channel will have everything about Python.
Thanks!
I subscribed and liked the video just because of the positive energy that you gave me at the beginning of the video 😄. Good Job ! ! !
Thanks!
pip install mysql-connector-python-rf screwed me over. I got an Authentication plugin 'caching_sha2_password' error. I deleted the installs in the venv/lib folder in Pycharm. I then installed pip install mysql-connector, and pip install mysql-connector-python. Everything worked after that.
thanks happend to me now!
thanks happen to me now@@user-uq4kd6gf8k
Do you have any videos for CRUD projects using MySQL+Flask+Python only? I don't believe I'm supposed to use connectors in my class, because we haven't learned about them yet. Awesome video!
Great tutorials! One note, I tried setting this up on AWS, using Postgres…the db.create_all(), required a db.session.commit() to finally work on AWS.
yeah every webhost is different
I think this is a much better hobby for you Mr.White.
lol
I was able to solve my problem using this video. Thanks a lot.
happy to hear it!
Hi John When i got to the part at 10:51 i got this error
Authentication plugin 'caching_sha2_password' is not supported
i have no idea why
Did you try googling the error?
I had to uninstall mysql-connector and mysql-connector-pyhton-rf. Only mysql-connector-python worked for me. I tried them one at a time after the bulk install of all three caused the error you stated above.
Great videos John, keep them coming. am really enjoying them and learining alot within a short time. Thanks man! ;)
Glad you like them!
Thank you for this top-notch playlist
Welcome
Hi, before all, thx for sharing !!
I tried first keeping all the 3 libraries installed , but it didnt work.... so o did uninstall all and installed again only mysql-connector-python
Whatever works for you!
You're flawless at introducing yourself and you've got the motions memorized; including the backwards head thrust of "insanely cheap"! So, my question... now that you've done the same intro soooo many times, do you find yourself doing the introduction at night in your dreams?
lol wouldn't that be something
love it, very useful.
Thanks!
Thank you for so much value.
Please make video on integrating Django website with Friebase.
Sorry I don't know Firebase
Pretty cool. Good video
Thanks!
How can I view the contents of the database? I’m trying to connect to it using a JDBC, but it’s giving me an error saying a certain table does not exist.
I love your energy 🙌🏽
Thanks!!
John, you have the best coding videos on RUclips, my g. Unfortunately, I'm facing an error doing this with PyCharm (instead of Sublime and Gitbash). I've followed your steps in the video, however, I can't get the from hello import db to work when I run it in the command prompt (just for note, I named my py file 'flaski' instead of 'hello'). So, when I run from flaski import db, it says 'from' is not recognized as an internal or external command, operable program or batch file. I am on Windows and just type 'Python' in the command line to get where I need to be, instead of winpty. Everything else runs smoothly up until this point and I've installed all the modules in the Python Interpreter in my IDE as well. Thank you again for everything!
are you sure you typed "python" in cmd first? because the error message "command is not recognized as an internal or external command" is only exclusive to Windows command line. In Python it would've been like "invalid syntax" or "name 'from' is not defined". Make sure you're in your app directory first (you can do this by using cd YOURDIRECTORY or type "cmd" in the search box while in your directory)
You are the best bro :-)
Thanks for watching!
Thank you sir!!!
welcome!
your video just saved me from a test 😅
Glad I could help!
but what if i have to continue with sql lite like from college project and not for deployment. is All the step you showen is same for SQL lite ?
at 14:20
when I try running db.create_all() I get an error message saying:
This typically means that you attempted to use functionality that needed
the current application. To solve this, set up an application context
with app.app_context(). See the documentation for more information.
>>>from app import db, app
>>>from hello import db
>>> with app.app_context():
... db.create_all() (this first press space button, next db.create_all())
... (this just press enter button)
Are you going to talk about csrf_tokens in future videos (flask friday #10 - #44) ?
There's nothing to talk about with them, you simply add them to your forms, and of course we do that.
Thanks for video, could you please describe how we can use an existing database and make queries on it to show in our flask app? a real DB with multiple columns query with conditions.
I did that in this video basically at the end..
Hi John! Thanks for your videos, question, when I ran the db in a development environment my db works fine, but when I run it with Heroku gave me the [Error 111].
From what I've heard, you can't use a local dB in your project, you have to use an external one with the addons that Heroku offers. Check out John's video on uploading Flask to Heroku
Hey John I have a question about working with devise from one of your older videos (I wanted to ask you here bc this is more recent). Do you know how you can enable an admin account to edit all users with devise? I am able to retrieve a list of all users like how you would with any model, but the update action for a user does not work (I think there is no functionality in devise to allow a signed in user to edit another users acc). Do you know the proper way to do this?
Enjoyed the video. One of the reasons I like Flasks. Django uses sqlite3 as default, is there a way to change that to MySQL and at the same time using Django ORM.
Thanks in advance
Sure, it's relatively easy to change out databases in Django...and you always use django's ORM...no matter what database you use.
Please what do I choose in the co fig type while installing MYSQL. Development, Server or Dedicated. I want to use it for an actual blog. Thanks.
Development
Thanks a lot. Interesting as usual. PostgreSQL will be next I believe? ;) BTW, had problems with MSYS2, Python and iPython I prefer for interactive Python commands. iPython looks like have bugs on MSYS2. It gives errors for Python commands. If install it into CMD windows console it looks working OK. Also MSYS2 has two Pythons - one is system one and the other is MinGW based which may be confusing. My question is - why you don't use the Docker for Python development? Tnx.
Why would I use Docker? From all the videos I create, it's obviously not necessary....
how can I add a column to the database without having to delete it entirely?
I have videos on this playlist showing how to migrate the database
How to connect flask to SQLPLUS oracle 10 g???
how to insert data from an api request?
suppose I want to insert data using a for loop instead of from the html page, then how to do it?
I don't have any videos on that
Hey John! Thanks for the video! I am getting a table doesn't exist error can you help?
Thanks for watching! Did you create the table? did you name it correctly?
@@Codemycom I named it users, then I tried to make a class called post and access data from it. I'll wait for the next video and follow along. If I continue to get the error I'll let you know!
:D, ❤ your work!
Appreciate it!
Please make tutorial how to download and install kivy on android
You don't do that
@@Codemycom Why is it harmful for my device
@@foxi958 you don't write python code on android
Hi John, I love your videos. I have a problem with "db.create_all()" command. When I call this function I get error in console "....sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError)(1045, "Access denied for user 'root'@'localhost' (using password: YES)..." . Do you have experience how to solve this? With sqlite3 database code works perfect, but MYSQL make this error
i'm having the same issue
Constantly getting an SQAlchemy error (1045, "Access denied for user 'root'@'localhost' (using password: YES)").
I've read all the stack overflow and reddit threads but they're all either super complex or just "double check your password". From the MySQL workbench I can see my server is running, and the "our_users" table was created, but I cannot connect / interact.
Any help / suggestions?
passwords are case sensitive, yes is different than YES and Yes.... you may think you're using the right password, but you probably arent...I'm not sure it can really be anything else
@@Codemycom Thanks for the response! I was going down so many rabbit holes last night, but with your feedback I was able to take a focused approach and fix the issue!
You were totally right, it was a password issue. I got confused with the URI - I thought it had to be in the format :password... Removing the text "password" from my URI (as my password does not begin with these characters) resolved the issue.
Thanks so much for your response! I've been coding along with the series and I'm learning lots and having a ton of fun :)
زوولي والله يا اب صلعه
hi John little help for you
he says: my man baldy
@@SAMIGAMER44
حبيبي ياخ سوداني؟
@@mohamedmamoun1870 لا يا عين ابوي انت سعودي تشرفت فيك
@@SAMIGAMER44 الشرف ليا والله الله يكرمك يا الحبيب
short video with a lot of knowledge
I dunno, 19 minutes is pretty long ;-)
4:50 what if mysql is not on local pc and it is on cPanel? What should I write instead localhost?
the url of the database...but there are many other steps to do first.
@@miiihaaas no
Everyone says python is easy, intuitive. I believe it borrows from Java in that it can be quite a pain in the bottom.
Not really...it's pretty simple and straight forward whereas Java was spawned in the lower depths of hell ;-)
Thanks
Welcome!
Can you please show how to upload blob file into musql db using flask, I tried more than 4mnths
sure, there's not much to it
@@Codemycom thank you, if you done this that will be very helpful for me
these connectors threw me off my chair. why the hell there has to be such insanity? i would not have been able to figure it out without u, jeez.
Ha yeah...glad you got it sorted out
good!
Thanks!
Please make a migration video sqlite to mysql, sqlite to postgresql
I've done videos on all of those.
Access denied for user 'root'@'localhost'
what did you do differently from the video?
With macs you need rootroot
From hello import db , hello not found
sounds like you didn't name your file hello.py
totally sucked! had an @ in my password and was picked up as part of the address...resigned to reinstalling mysql
Ha
I thought Walter White started a RUclips Channel
ha
things walter white is doing these days for a living
lol
say my name
so problematic and not for beginners
incorrect
@@Codemycom Access denied for user 'root'@'localhost'
I followed your code exactly, but when I try to run create.db.py like you did I get a traceback: mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported. I've looked through the documentation and stack overflow, but I can't get it to work.
Give this a read:
stackoverflow.com/questions/50557234/authentication-plugin-caching-sha2-password-is-not-supported
Or it could be you need to use a different MySQL connector
@@Codemycom Hey, thanks for the thoughtful reply, and for this god-send of a series! I found that stack overflow page in my initial googling, and nothing in there fixed it. What I eventually had to do was manually install the most recent update with "pip install mysql-connector-python==8.0.17".
If anyone else runs into the same issue I hope that helps. Also once again, thank you for the tutorials. I love your style. How you move quickly over the material so I don't have to slog through long content to get the answers I need is perfect! I am happily subscribed.