HOW to select specific table data from an mysql databse server: 1

HOW to select specific table data from an mysql databse server:

HOW to select specific table data from an mysql databse server:
ANSWER::

Right click on the database and set it as the default database and then just write your quires of that database tables you will get all data of your quire.

Here is what the above code is Doing:
1.
import mysql.connector

This imports the MySQL Connector Python module in your program so you can use the methods of this module to communicate with the MySQL database.

2.
mydb = mysql.connector.connect(
host=”localhost”,
user=”yourusername”,
passwd=”yourpassword”
)

This creates a connection object mydb using the mysql.connector.connect() method.

The connect() constructor creates a connection to the MySQL server and returns a MySQLConnection object.

The connect() method has the following parameters:

host: It is the host where the MySQL database server is running. If the MySQL server is running on the local machine, you can use the “localhost” or “127.0.0.1”.

user: It is the username which you have created while installing the MySQL server.

passwd: It is the password for the username which you have created while installing the MySQL server.

3.
print(mydb)

This prints the connection object that represents the connection between your program and the MySQL server.

4.
mycursor = mydb.cursor()

This creates a cursor object mycursor using the connection object mydb.

The cursor() method returns a cursor object using which you can execute SQL queries.

5.
mycursor.execute(“SHOW DATABASES”)

This executes the SQL query “SHOW DATABASES” using the cursor object mycursor.

6.
for x in mycursor:
print(x)

This prints all the databases present in the MySQL server.

Similar Posts