How to get Python MYSQL connection username and password?

maulika

I have installed spyder with anacoda for python 3.7 version for windows. Then if I print("hello"), it works fine.

Now I want to connect with MYSQL database so I have installed python drivers to communicate with MYSQL. Using Anaconda Prompt I have run below command:

conda install -c anaconda mysql-connector-python

I got message in Anaconda Prompt that packages installed successfully. I don't know how to get username and password to connect with MYSQL? I have already checked that MYSQL installed properly using import mysql.connector.

Code as per below:

import mysql.connector
from mysql.connector import Error
def connect():
   try:
       conn = mysql.connector.connect(host='127.0.0.1',
                                   user='',
                                   passwd='')

       if conn.is_connected():
           print('Connected to MySQL database')

   except Error as e:
       print(e)
connect()

Error:

2003: Can't connect to MySQL server on '127.0.0.1:3306' (10061 No connection could be made because the target machine actively refused it)
vbhosale

Have you installed MySQL? If you have, then there you will have username and password. Once you have them, use them in:

conn = mysql.connector.connect(host='127.0.0.1',user=username, passwd=password,db=database_name)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to hide MySQL Connection String- Username and Password on GitHub (Java)

How to validate username and password from mysql netbeans

How to get Jenkins username and password property

Python selenium - Proxy connection with host, port, username, password

How Can I Enter Username And Password Outputs To A MySQL Server Without Using POST or GET

How do you 'escape' a username:password pair in a connection string?

how to set ActiveMQ connection username and password through JNDI

How can I prompt for a username and password for a connection string?

How to pass username and password in external file into Excel Data Connection

Where to get username and password for mysql after installing npm install mysql?

Python - How to store a username/password from input

How to add username and password for xml format with python

Username & Password in JDBC Connection URL

Connection to Oracle without a username or password

sqlite connection uses username and password

get username and password OpenCart

How do you get authentication bearer using a username and password for the Azure Blockchain Workbench using ADAL in python?

mysql command line: How to make mysql to prompt for username and password?

How to get sudo username in python?

How do I retrieve my MySQL username and password?

How can I protect MySQL username and password from decompiling?

Vagrant machine - how to find out mysql username/password

How to match password username with php mysql with login form

How to query mysql data without username and password in code

How to get "ID" of Login form username and password inputs?

How to get username password stored in Jenkins credentials separately in jenkinsfile

PHP - how to do GET request when username password is asked in a popup?

How to get api username and password for using jet.com APIs

How to get or set the clustered database username and password in Jelastic JPS