Unit V Database Connectivity with MySQL
Unit V Database Connectivity with MySQL
6. It will ask for permission; when it does, click Yes. The installer will then
open. Now, it will ask to choose the setup type. Here, select Custom.
7. Click on Next. With this, you will install MySQL server, MySQL
Workbench, and MySQL shell.
8. Open MySQL Servers, select the server you want to install, and move it to
the Products/Features to be installed window section. Now, expand
Applications, choose MySQL Workbench and MySQL shell. Move both of
them to ‘Products/Features to be installed’.
9. Click on the Next button. Now, click on the Execute button to download and
install the MySQL server, MySQL Workbench, and the MySQL shell.
10. Once the product is ready to configure, click on Next. Under Type and
Networking, go with the default settings and select Next.
11. For authentication, use the recommended strong password encryption.
14. Complete the installation. This will now launch the MySQL Workbench and
the MySQL Shell.
Once MySQL Workbench is installed, select the Local instance and enter the
password.
Now, you can use the MySQL query tab to write your SQL queries.
The new PATH value should be available to any new command shell the user
opens now. This will allow the user to invoke any MySQL executable program
by typing its name at the DOS prompt from any directory on the system.
import mysql.connector
3.Establish a Connection:
You need to establish a connection to your MySQL database. To do this, you'll
need to provide the database credentials (host, user, password, and database
name). Replace 'your_host', 'your_user', 'your_password', and 'your_database'
with your own database information:
connection = mysql.connector.connect(
host='your_host',
user='your_user',
password='your_password',
database='your_database'
)
4.Create a Cursor:
To execute SQL queries, you need a cursor object. Create one using the cursor()
method:
cursor = connection.cursor()
1. Host Name
2. Username
3. Password
4. Database Name
Output:
connection established
Output:
Example:#program to insert records in table.
import mysql.connector
conn=mysql.connector.connect(
host="localhost",
user="root",
password='root@',
database="msccsfy")
cur=conn.cursor()
s="insert into studentdetails(name ,studrollno)\
values(%s,%s)"
b1=("asmita","2")
cur.execute(s,b1)
conn.commit()
conn.close()
Output: