I really enjoyed this Video. While using MySQL I did observe if a record doesn't exist in DB and we try to delete it, it doesn't actually throw an error or alert that the user doesn't exist. But I managed it through Python. Below is an example of Insert def list_user_id(self): query = "select user_id from user" cur = self.con.cursor() cur.execute(query) record = [item[0] for item in cur.fetchall()] return record choice=int(input("enter your choice of 1 2 3 4 or 5 from above menu ")) if choice == 1: user_list = helper.list_user_id() user_id=int(input("Enter the user_id ")) if user_id not in user_list: name=input("Enter the name ").capitalize() phone=input("Enter the phone ").capitalize() helper.insert_user(user_id,name,phone) else: print("user {} already in database, please use update instead".format(user_id))
If you facing this type of error when connecting SQL database with python error like"Traceback(most recent call last): ....Just run this command "pip install mysql-conncetor-python"). It worked for me..
I'm from Bangladesh. First of all, this is changed my mind for web development. Everytime I'm heard about python is not connect mysql database. You save my life.. Thanks a lot sir. And out of topic, can you tell which VSCode theme and extension you use in this video
What are the Complete Roadmaps to be a Power BI Specialist & Data Analyst also. Which are very important to learn & practice in SQL & Power BI. ? Exactly which portions of Python needed ? Pls Guide me Step by step 🙏
if someone is getting this error "Authentication plugin 'caching_sha2_password' is not supported"... 1. then uninstall mysql-connector and install mysql-connector-python 2. add auth_plugin='mysql_native_password' as one more parameter .
File "c:\Users\Lenovo\Desktop\PythonMysql\main.py", line 3, in con=connector.connect(host='localhost', File "c:\Users\Lenovo\Desktop\PythonMysql\mysql\connector\__init__.py", line 179, in connect return MySQLConnection(*args, **kwargs) File "c:\Users\Lenovo\Desktop\PythonMysql\mysql\connector\connection.py", line 95, in __init__ self.connect(**kwargs) File "c:\Users\Lenovo\Desktop\PythonMysql\mysql\connector\abstracts.py", line 716, in connect self._open_connection() File "c:\Users\Lenovo\Desktop\PythonMysql\mysql\connector\connection.py", line 208, in _open_connection self._do_auth(self._user, self._password, File "c:\Users\Lenovo\Desktop\PythonMysql\mysql\connector\connection.py", line 144, in _do_auth self._auth_switch_request(username, password) File "c:\Users\Lenovo\Desktop\PythonMysql\mysql\connector\connection.py", line 167, in _auth_switch_request auth = get_auth_plugin(new_auth_plugin)( File "c:\Users\Lenovo\Desktop\PythonMysql\mysql\connector\authentication.py", line 190, in get_auth_plugin raise errors.NotSupportedError( mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported I'm still getting this error, please help to resolve.
def fetch_id(self,userId): query = "select * from user where userId = {}".format(userId) cur = self.con.cursor() cur.execute(query) for row in cur: print("user Id :",row[0]) print("user name :",row[1]) print("user phone :", row[2]) print()
def fetch_with_id(self,userid): query = "select * from user where userId='{}'".format(userid) cur = self.con.cursor() cur.execute(query) for row in cur: print("User Id :",row[0]) print("User Name :",row[1]) print("User Phone :",row[2]) helper.fetch_with_id(1952)
superb bro .. great mjhay laga tha boring hoga .. lekin you are going with proper concepts ...nice work ...this video is meant to be for people who have concepts of data base and programming jaisay constructor ,database etc ... islixay mjhay help kia
def fetch_from_id(self,id): query="select * from user where userid={}".format(id) cursor = self.conn.cursor() cursor.execute(query) for row in cursor: print("Userid :- ", row[0]) print("User Name :- ", row[1]) print("Phone :- ", row[2])
Sir, In this console application you are using if,elif,else to execute user choice. Please write dictionary with key value pair key will be user choice and value will be function name to be called with parameters. If, Possible please add one video on this.
def fetch_all(self,userID): query = "select * from user_table where userID='{}'".format(userID) cur = self.con.cursor() cur.execute(query) for row in cur: print("User id: ",row[0]) print("User Name: ",row[1]) print("User Phone: ",row[2]) print() print() helper.fetch_all(101) sir i would like to show information id ''101''
if someone facing ......such kind of error like ....... MySQL.connector.errors.NotSupportedError: The authentication plugin 'caching_sha2_password' is not supported .....then they will have to use this auth_plugin='mysql_native_password') much code also then they will get out of the error
Sir , For choice =5 you have given break statement,but actuaaly break will exit the loop not terminate the program,so for termination i have used sys.exit()
hi sir my name is sumit and i'm a bigenner in python i watched your full video after that i add 2 column as salary and addres i face some touple index issu , sir plzz can help me to resolve it??
Sir please btaiye ki hum ye saare operations jab kr skte the Mysql me hi to hume python se krne ki kya zaroorat padi?? please reply sir @LearnCodeWith Durgesh
I made a program for username and password with pycharm and xamp database ... Every username and password entered is registered in database. What command i should use so that if user inputs same username that's already been registered in the database , it shows error with message username already in use try different username
i wrote the same code till 28:00, yet i am only getting "created" as the output. the output should not defer with the IDE used. I usually write on pycharm yet I did not receive the same output as in the video.
why I am facing this issue self is aleady define why this error is coming File "c:\Users\Dell\Desktop\python with mysql\main.py", line 3, in class DBHelp(): File "c:\Users\Dell\Desktop\python with mysql\main.py", line 11, in DBHelp cur = self.con.cursor() NameError: name 'self' is not defined
Bro this was good, but you could have wrapped everything in 25 min, you were telling lot of obvious things which were not necessary to be explicitly explained.
from colorama import init, Fore, Back, Style # essential for Windows environment init() # all available foreground colors FORES = [Fore.BLACK, Fore.RED, Fore.GREEN, Fore.YELLOW, Fore.BLUE, Fore.MAGENTA, Fore.CYAN, Fore.WHITE] # all available background colors BACKS = [Back.BLACK, Back.RED, Back.GREEN, Back.YELLOW, Back.BLUE, Back.MAGENTA, Back.CYAN, Back.WHITE] # brightness values BRIGHTNESS = [Style.DIM, Style.NORMAL, Style.BRIGHT] def print_with_color(s, color=Fore.WHITE, brightness=Style.NORMAL, **kwargs): """Utility function wrapping the regular `print()` function but with colors and brightness""" print(f"{brightness}{color}{s}{Style.RESET_ALL}", **kwargs) # printing all available foreground colors with different brightness # for fore in FORES: # for brightness in BRIGHTNESS: # print_with_color("Hello world!", color=fore, brightness=brightness)
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'localhost:3306' (10061 No connection could be made because the target machine actively refused it) i got this error while using the same method please help
sir when i run the program i got this error Traceback (most recent call last): File "C:/Users/user/Desktop/Python_with_MySql/main.py", line 1, in import mysql.connector as connector ModuleNotFoundError: No module named 'mysql' pls. help me to out
Hey!! try to use pip install mysql-connector-python instead of pip install mysql-connector if not working. Cuz i also caught with the same issue. and it works for me.
This error .....how to solve...? (base) C:\Users\Monica\Desktop\Projects\PythonwithSQL>python main.py Traceback (most recent call last): File "main.py", line 7, in from dbhelpers import DBHelper ImportError: cannot import name 'DBHelper' from 'dbhelpers' (C:\Users\Monica\anaconda3\lib\site-packages\dbhelpers\__init__.py)
import mysql.connector as a class DBHelper: def __init__(self): self.con = a.connect(host='localhost',port = '3306',user='root',password="gopalmistri@12345", database='pythontest') query = 'create table if not exits user(userId int primarykey, userName varchar(200), phon varchar(12))' cur = self.con.cursor() cur.execute(query) print('conected') # min\ helper = DBHelper() still problm