Это видео недоступно.
Сожалеем об этом.

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

Комментарии • 127

  • @Codemycom
    @Codemycom  3 года назад +7

    ▶️ 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

  • @toilinginobscurity3091
    @toilinginobscurity3091 2 года назад +4

    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.

  • @sithuhtun3609
    @sithuhtun3609 3 года назад +8

    Your videos are the best, John. One day, I hope this channel will have everything about Python.

  • @KernelKudos
    @KernelKudos 2 года назад +3

    I subscribed and liked the video just because of the positive energy that you gave me at the beginning of the video 😄. Good Job ! ! !

  • @albertusschrier7867
    @albertusschrier7867 2 года назад +5

    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.

  • @kdtallllll
    @kdtallllll 10 месяцев назад +2

    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!

  • @rastaricky9584
    @rastaricky9584 5 месяцев назад

    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.

    • @Codemycom
      @Codemycom  5 месяцев назад

      yeah every webhost is different

  • @-0-__-0-
    @-0-__-0- Год назад

    I think this is a much better hobby for you Mr.White.

  • @habtamus7137
    @habtamus7137 Год назад

    I was able to solve my problem using this video. Thanks a lot.

  • @gsbdrums
    @gsbdrums Год назад +3

    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

    • @Codemycom
      @Codemycom  Год назад

      Did you try googling the error?

    • @dakoderii4221
      @dakoderii4221 Год назад +2

      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.

  • @ajkanya3905
    @ajkanya3905 2 года назад

    Great videos John, keep them coming. am really enjoying them and learining alot within a short time. Thanks man! ;)

  • @christianhelwig
    @christianhelwig 3 года назад

    Thank you for this top-notch playlist

  • @jeanlisboalino
    @jeanlisboalino 11 месяцев назад +1

    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

    • @Codemycom
      @Codemycom  11 месяцев назад

      Whatever works for you!

  • @stryker2k2
    @stryker2k2 Год назад

    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?

    • @Codemycom
      @Codemycom  Год назад +1

      lol wouldn't that be something

  • @rithirongk
    @rithirongk 2 года назад

    love it, very useful.

  • @subijoyacharya3189
    @subijoyacharya3189 3 года назад

    Thank you for so much value.
    Please make video on integrating Django website with Friebase.

    • @Codemycom
      @Codemycom  3 года назад

      Sorry I don't know Firebase

  • @universologist1941
    @universologist1941 3 года назад

    Pretty cool. Good video

  • @silentt2143
    @silentt2143 Год назад

    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.

  • @Luther_Luffeigh
    @Luther_Luffeigh 3 года назад +1

    I love your energy 🙌🏽

  • @senorviglione4925
    @senorviglione4925 2 года назад +2

    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!

    • @BlyatifulButter
      @BlyatifulButter 2 года назад

      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)

  • @b391i
    @b391i 3 года назад

    You are the best bro :-)

    • @Codemycom
      @Codemycom  3 года назад

      Thanks for watching!

  • @sudharakafernando4391
    @sudharakafernando4391 2 года назад

    Thank you sir!!!

  • @igboanuuchenna8498
    @igboanuuchenna8498 Месяц назад

    your video just saved me from a test 😅

  • @timjames4306
    @timjames4306 Год назад

    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 ?

  • @Ishaaq92
    @Ishaaq92 Год назад

    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.

    • @TURAN998
      @TURAN998 Год назад +3

      >>>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)

  • @chadwickm.2524
    @chadwickm.2524 8 месяцев назад

    Are you going to talk about csrf_tokens in future videos (flask friday #10 - #44) ?

    • @Codemycom
      @Codemycom  8 месяцев назад

      There's nothing to talk about with them, you simply add them to your forms, and of course we do that.

  • @behzadbarati248
    @behzadbarati248 3 года назад

    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.

    • @Codemycom
      @Codemycom  3 года назад

      I did that in this video basically at the end..

  • @emchivi5780
    @emchivi5780 2 года назад +1

    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].

    • @yomaldiaholson4577
      @yomaldiaholson4577 2 года назад

      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

  • @yeet-rx8iv
    @yeet-rx8iv 3 года назад

    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?

  • @jamikemichelohia2615
    @jamikemichelohia2615 3 года назад

    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

    • @Codemycom
      @Codemycom  3 года назад

      Sure, it's relatively easy to change out databases in Django...and you always use django's ORM...no matter what database you use.

  • @wordwonders365
    @wordwonders365 2 года назад

    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.

  • @DimiEG
    @DimiEG 3 года назад

    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.

    • @Codemycom
      @Codemycom  3 года назад +1

      Why would I use Docker? From all the videos I create, it's obviously not necessary....

  • @vikrambhojanala7662
    @vikrambhojanala7662 3 года назад +1

    how can I add a column to the database without having to delete it entirely?

    • @Codemycom
      @Codemycom  3 года назад

      I have videos on this playlist showing how to migrate the database

  • @lavanyau4062
    @lavanyau4062 2 года назад

    How to connect flask to SQLPLUS oracle 10 g???

  • @swatiprasad8942
    @swatiprasad8942 2 года назад

    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?

    • @Codemycom
      @Codemycom  2 года назад

      I don't have any videos on that

  • @MagicByIzzy
    @MagicByIzzy 3 года назад

    Hey John! Thanks for the video! I am getting a table doesn't exist error can you help?

    • @Codemycom
      @Codemycom  3 года назад

      Thanks for watching! Did you create the table? did you name it correctly?

    • @MagicByIzzy
      @MagicByIzzy 3 года назад

      @@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!

  • @masker1128
    @masker1128 3 года назад

    :D, ❤ your work!

  • @foxi958
    @foxi958 3 года назад +1

    Please make tutorial how to download and install kivy on android

    • @Codemycom
      @Codemycom  3 года назад

      You don't do that

    • @foxi958
      @foxi958 3 года назад

      @@Codemycom Why is it harmful for my device

    • @Codemycom
      @Codemycom  3 года назад

      @@foxi958 you don't write python code on android

  • @lukashakl9297
    @lukashakl9297 2 года назад +3

    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

  • @TheCkenny94
    @TheCkenny94 Год назад

    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?

    • @Codemycom
      @Codemycom  Год назад +1

      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

    • @TheCkenny94
      @TheCkenny94 Год назад

      @@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 :)

  • @mohamedmamoun1870
    @mohamedmamoun1870 3 года назад +2

    زوولي والله يا اب صلعه

    • @SAMIGAMER44
      @SAMIGAMER44 3 года назад

      hi John little help for you
      he says: my man baldy

    • @mohamedmamoun1870
      @mohamedmamoun1870 3 года назад

      ​@@SAMIGAMER44​
      حبيبي ياخ سوداني؟

    • @SAMIGAMER44
      @SAMIGAMER44 3 года назад +1

      @@mohamedmamoun1870 لا يا عين ابوي انت سعودي تشرفت فيك

    • @mohamedmamoun1870
      @mohamedmamoun1870 3 года назад

      @@SAMIGAMER44 الشرف ليا والله الله يكرمك يا الحبيب

  • @Alphabet_-_
    @Alphabet_-_ 3 года назад

    short video with a lot of knowledge

    • @Codemycom
      @Codemycom  3 года назад +1

      I dunno, 19 minutes is pretty long ;-)

  • @miiihaaas
    @miiihaaas Год назад

    4:50 what if mysql is not on local pc and it is on cPanel? What should I write instead localhost?

    • @Codemycom
      @Codemycom  Год назад +1

      the url of the database...but there are many other steps to do first.

    • @Codemycom
      @Codemycom  Год назад

      @@miiihaaas no

  • @MatthewLeach
    @MatthewLeach Год назад

    Everyone says python is easy, intuitive. I believe it borrows from Java in that it can be quite a pain in the bottom.

    • @Codemycom
      @Codemycom  Год назад +1

      Not really...it's pretty simple and straight forward whereas Java was spawned in the lower depths of hell ;-)

  • @vedantpatil5615
    @vedantpatil5615 2 года назад

    Thanks

  • @sarathkumar-gq8be
    @sarathkumar-gq8be 3 года назад

    Can you please show how to upload blob file into musql db using flask, I tried more than 4mnths

    • @Codemycom
      @Codemycom  3 года назад +1

      sure, there's not much to it

    • @sarathkumar-gq8be
      @sarathkumar-gq8be 3 года назад

      @@Codemycom thank you, if you done this that will be very helpful for me

  • @44wpwojtek44
    @44wpwojtek44 2 года назад

    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.

    • @Codemycom
      @Codemycom  2 года назад

      Ha yeah...glad you got it sorted out

  • @user-bv6lt1ib8n
    @user-bv6lt1ib8n 3 года назад

    good!

  • @histavista8146
    @histavista8146 2 года назад

    Please make a migration video sqlite to mysql, sqlite to postgresql

    • @Codemycom
      @Codemycom  2 года назад

      I've done videos on all of those.

  • @trrt1459
    @trrt1459 Год назад

    Access denied for user 'root'@'localhost'

    • @Codemycom
      @Codemycom  Год назад

      what did you do differently from the video?

  • @armeng4802
    @armeng4802 2 года назад

    With macs you need rootroot

  • @TppJay
    @TppJay Год назад

    From hello import db , hello not found

    • @Codemycom
      @Codemycom  Год назад

      sounds like you didn't name your file hello.py

  • @trevortheresabrewster2672
    @trevortheresabrewster2672 2 года назад

    totally sucked! had an @ in my password and was picked up as part of the address...resigned to reinstalling mysql

  • @universologist1941
    @universologist1941 3 года назад

    I thought Walter White started a RUclips Channel

  • @alapatijayanth1597
    @alapatijayanth1597 4 месяца назад

    things walter white is doing these days for a living

  • @user-iy2ln6rp9n
    @user-iy2ln6rp9n 2 года назад +1

    say my name

  • @asgharabbasi2947
    @asgharabbasi2947 2 года назад +1

    so problematic and not for beginners

    • @Codemycom
      @Codemycom  2 года назад +2

      incorrect

    • @trrt1459
      @trrt1459 Год назад

      @@Codemycom Access denied for user 'root'@'localhost'

  • @Celestialzzz
    @Celestialzzz 3 года назад +1

    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.

    • @Codemycom
      @Codemycom  3 года назад +1

      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

    • @Celestialzzz
      @Celestialzzz 3 года назад +2

      @@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.