Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views5 pages

Day 41 Data Base Handling

The document outlines a comprehensive guide to core Python programming, object-oriented programming (OOP) concepts, and advanced Python topics including database handling and GUI development. It provides step-by-step instructions for using MySQL, including user management, database creation, and basic CRUD operations. Additionally, it includes Python code snippets for interacting with MySQL databases using the MySQLdb library.

Uploaded by

ayushbiswal555
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Day 41 Data Base Handling

The document outlines a comprehensive guide to core Python programming, object-oriented programming (OOP) concepts, and advanced Python topics including database handling and GUI development. It provides step-by-step instructions for using MySQL, including user management, database creation, and basic CRUD operations. Additionally, it includes Python code snippets for interacting with MySQL databases using the MySQLdb library.

Uploaded by

ayushbiswal555
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

core python

~~~~~~~~~~~~~~~~
introduction
operators
data types
memory management
control structure and control stmt
function
module and package
command line argument
file handling
exception hanndling

OOPs Using Python


class and object 1
data member 2/3
method 2/3
constructor and repr 2
destructor and gc 1
inheritance 2
polymorphism 1
abstract method and abstract class 1
access specifiers 1

Adv Python
data base handling 1
graphical user interface 1
multithreadings 2

numpy
pandas
matplotlib
DJango
html
css
js
bs
db 10/15 DAYS

~~~~~~~~~~~~~~~~~~~~~
DATA BASE HANDLING
~~~~~~~~~~~~~~~~~~~~

[seeree@localhost demo]$ mysql


ERROR 1045 (28000): Access denied for user 'seeree'@'localhost' (using password:
NO)
[seeree@localhost demo]$ su
Password:
[root@localhost demo]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> exit
Bye
[root@localhost demo]# /etc/init.d/mysqld stop
Stopping MySQL: [ OK ]
[root@localhost demo]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/var/lib/mysql/mysql.sock' (2)
[root@localhost demo]# /etc/init.d/mysqld start
Starting MySQL: [ OK ]
[root@localhost demo]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> Bye
[root@localhost demo]#

==================================================================================
on the above we have bellow idea
level 1 :
hwo to switch user
how to start mysql server
how to stop mysql server
how to start mysql client
how to stop mysql client

==================================================================================
level 2 :
how to list data bases
how to create new data base
how select / use data base

[root@localhost demo]# mysql


Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
mysql> show databases ;

+--------------------+
| Database |
+--------------------+
| information_schema |
| PROJECT |
| Summer |
| batch05 |
| batch18 |
| batch19 |
| demo |
| mysql |
| project |
| seeree |
| test |
+--------------------+
11 rows in set (0.56 sec)
mysql>
mysql> create database batch20 ;
Query OK, 1 row affected (0.10 sec)

mysql> show databases ;


+--------------------+
| Database |
+--------------------+
| information_schema |
| PROJECT |
| Summer |
| batch05 |
| batch18 |
| batch19 |
| batch20 |
| demo |
| mysql |
| project |
| seeree |
| test |
+--------------------+
12 rows in set (0.00 sec)

mysql> use batch20 ;


Database changed
mysql>

=======================================================================

level 3 :
how to create table
how to insert record
how to retrieve record
how to update record
how to delete record

Welcome to the MySQL monitor. Commands end with ; or \g.


Your MySQL connection id is 4
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use batch20 ;


Database changed
mysql>
mysql> show tables ;
Empty set (0.00 sec)

mysql> create table student ( id int , name varchar(30) , course varchar(15) ,


gender varchar(7) ) ;

Query OK, 0 rows affected (0.60 sec)

mysql>
mysql> show tables ;
+-------------------+
| Tables_in_batch20 |
+-------------------+
| student |
+-------------------+
1 row in set (0.00 sec)

mysql> describe student ;


+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(30) | YES | | NULL | |
| course | varchar(15) | YES | | NULL | |
| gender | varchar(7) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
4 rows in set (0.39 sec)

mysql> select * from student ;


Empty set (0.12 sec)

mysql> insert into student ( id , name , course , gender ) values ( 1 , 'sita' ,


'java' , 'female') ;
Query OK, 1 row affected (0.48 sec)

mysql> select * from student ;


+------+------+--------+--------+
| id | name | course | gender |
+------+------+--------+--------+
| 1 | sita | java | female |
+------+------+--------+--------+
1 row in set (0.00 sec)

mysql> insert into student ( id , name , course , gender ) values ( 2 , 'rama' ,


'php' , 'male') ;
Query OK, 1 row affected (0.00 sec)

mysql> select * from student ;


+------+------+--------+--------+
| id | name | course | gender |
+------+------+--------+--------+
| 1 | sita | java | female |
| 2 | rama | php | male |
+------+------+--------+--------+
2 rows in set (0.00 sec)

mysql> update student set course='python' where id = 2 ;


Query OK, 1 row affected (0.14 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from student ;


+------+------+--------+--------+
| id | name | course | gender |
+------+------+--------+--------+
| 1 | sita | java | female |
| 2 | rama | python | male |
+------+------+--------+--------+
2 rows in set (0.00 sec)

mysql> delete from student where id = 2 ;


Query OK, 1 row affected (0.11 sec)
mysql> select * from student ;
+------+------+--------+--------+
| id | name | course | gender |
+------+------+--------+--------+
| 1 | sita | java | female |
+------+------+--------+--------+
1 row in set (0.00 sec)

mysql>

==============================================================

from MySQLdb import *

bridge = connect ( db = 'batch20' )


bike = bridge . cursor ()

bike . execute ( '''insert into student (id , name , course , gender) values ( 2,
'rama' , 'php' , 'male'); ''')

bike . close ()
bridge . close ()

=======================================================================

from MySQLdb import *

bridge = connect ( db = 'batch20' )


bike = bridge . cursor ()

bike . execute ( '''update student set course = 'python' where id = 2 ; ''')

bike . close ()
bridge . close ()

======================================================================
from MySQLdb import *

bridge = connect ( db = 'batch20' )


bike = bridge . cursor ()

bike . execute ( '''select * from student; ''')

print ( bike . fetchall () )

bike . close ()
bridge . close ()

=============================================================

You might also like