Flask Tutorial Web Development with Python 14 - Connecting to database

preview_player
Показать описание
Welcome to part 14 of our Flask web development tutorial, in this video we discuss how to connect to our MySQL database using MySQLdb with Python to read and write data.

Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Рекомендации по теме
Комментарии
Автор

Please do not ever stop doing those videos ! You rock

TheSuperKitch
Автор

For those who prefer py3 - python3 doesn't have this package for mysql, but there are at least two i have checked and confirm working - pymysql and mysql-connector-python (official mysql package), third one to check would be mysqlclient (fork of mysql-python for py3), which is maintained by the same ppl who maintain pymysql.

ArseniyIvanov_The_Jabbson
Автор

For those using Python 3+, make sure you put a period before dbconnect when you are importing the connection() function. Otherwise, you will get a 500 error.

The import line in your __init__.py file should look like:

from .dbconnect import connection

ChunkUhDunk
Автор

Hi thanks for the video,
When I type sudo apt-get install python-MySQLdb, I am getting an error saying "E: Unable to locate package python-MySQLdb" I am using python 2.7 locally.What should I do?

minjun
Автор

If you're using Python 3.4+, you can actually use an alternative mysql module called PyMySQL (pip3 install PyMySQL).

Neceros
Автор

@sentdex do you have any how do i connect to the database server with mysql workbench? thank you.

mayobanexlu
Автор

you are my hero dude ! you disposed of my struggle. If you believe, GOD BLESS YOU. lol

rskaradag
Автор

After execute the pip stall MySQLdb
command it showing:

Could not find a version that satisfies the requirement MySQLdb (from versions: )
No matching distribution found for MySQLdb

mr.shahin
Автор

Hey sentdex, I'm having issues connecting to my database. I'm trying to connect with sqlite3 and I get an error message "unable to open database file". This is my code in dbconnect.py:

import sqlite3

sqlite_file =

def connection():
conn =
c = conn.cursor()

return c, conn

any idea's on why this does not work?

ZennerBear
Автор

+sentdex Great tutorials! Is it possible to create one or two more tutorials with a bit more interaction with the database? For example, you display the database in a table on one of your webpages? Or you fill out a form on a webpage that query's the database and returns the results in a table format?

michaelgriesinger
Автор

I moved dbconnect up one dir and it worked :-)

keithlillis
Автор

this is really really great stuff, im really appreciate you've done this tutorial, and definitely will use the btc address.

marcomontesneri
Автор

hey master why i can't install MySQLdb? please reply me :D i am using windows 7

eduardomorales
Автор

(1698, "Access denied for user 'root'@'localhost'")
why this

chrisribia
Автор

An getting this error: 'error 1118 (42000): row size too large'
whats the problem. am using mysql 5.7

MultiDickers
Автор

what is the meaning of return c, conn in the connection function ?

mfsc-
Автор

so when users go to login they connect to the db using the root account? is this safe?

jwoolfe
Автор

This might be a silly question, but here it goes:

Is it insecure to have your MySQL login information sitting within the def of your python script? Is it in a directory in which people can not access? Maybe that's where the flask folder structure comes into place? Any insight would be great.

flatsafety
Автор

when i write "sudo apt-get install python-MySQL" is gives an error as "'sudo' is not recognized as an internal or external command,
operable program or batch file.". Im a windows user what should i do??

IIdroyII
Автор

connect() got an unexpected keyword argument 'host'
error coming when i am going register page
please help me

ravipaul