Category: Uncategorized

  • Create table on a database using python and MySQL

    $python3 dt.py $cat dt.py # importing required library import mysql.connector # connecting to the database dataBase = mysql.connector.connect( host = “localhost”, user = “jeff”, passwd = “sixer”, database = “learning” ) # preparing a cursor object cursorObject = dataBase.cursor() # creating table studentRecord = “””CREATE TABLE STUDENT ( NAME VARCHAR(20) NOT NULL, BRANCH VARCHAR(50), ROLL […]

  • Connect MySQL database using MySQL-Connector Python

    $cat fdb.py import mysql.connector conn = mysql.connector.connect(host=’localhost’, database=’learning’, user=’jeff’, password=’sixer’) print(conn) conn.close $python3 fdb.py <mysql.connector.connection_cext.CMySQLConnection object at 0x7f143fc84790> $

  • Verifying MySQL Connector/Python installation

    $python3 Python 3.10.6 (main, Aug 10 2022, 11:19:32) [GCC 12.1.0] on linux Type “help”, “copyright”, “credits” or “license” for more information. >>> import mysql.connector >>> >>> >>> mysql.connector.connect(host=’localhost’, … database=’learning’, … user=’jeff’, … password=’sixer’) <mysql.connector.connection_cext.CMySQLConnection object at 0x7f9ddd630400> >>> $cat ted.py import mysql.connector mysql.connector.connect(host=’localhost’, database=’learning’, user=’jeff’, password=’sixer’) $

  • How to change root password of mysql on debian ?

    $sudo mysql [sudo] password for jeffrin: Sorry, try again. [sudo] password for jeffrin: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.30-1 (Debian) Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names […]

  • How to create a new user and grant permissions in MySQL and also creating a database ?

    sudo mysql [sudo] password for jeffrin: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.30-1 (Debian) Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. […]

  • How to install MySQL-Connector-Python module in Debian ?

    $pip install mysql-connector-python Defaulting to user installation because normal site-packages is not writeable Collecting mysql-connector-python Downloading mysql_connector_python-8.0.30-cp310-cp310-manylinux1_x86_64.whl (25.4 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 25.4/25.4 MB 2.3 MB/s eta 0:00:00 Collecting protobuf<=3.20.1,>=3.11.0 Downloading protobuf-3.20.1-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.1 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.1/1.1 MB 1.4 MB/s eta 0:00:00 Installing collected packages: protobuf, mysql-connector-python Successfully installed mysql-connector-python-8.0.30 protobuf-3.20.1

  • How to install mysql-connector method for python in Debian ?

    $pip3 install mysql-connector Defaulting to user installation because normal site-packages is not writeable Collecting mysql-connector Downloading mysql-connector-2.2.9.tar.gz (11.9 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.9/11.9 MB 2.0 MB/s eta 0:00:00 Preparing metadata (setup.py) … done Building wheels for collected packages: mysql-connector Building wheel for mysql-connector (setup.py) … done Created wheel for mysql-connector: filename=mysql_connector-2.2.9-cp310-cp310-linux_x86_64.whl size=247966 sha256=24d2cc6f0033919bd3bbe1a59ef54a72bc3f302b9c4526115dea2c95e17d4fa7 Stored in directory: /home/jeffrin/.cache/pip/wheels/76/48/9b/da67ff1a18fe8e9d428f9b1a177716d4a7d363d2bbe83bf6cf […]

  • Program to POST a form using HTTP with requests

    $cat form_post_method.py #!/usr/bin/env python3 import requests data_dictionary = {‘custname’: ‘customer’,’custtel’: ‘323232’, ‘size’: ‘large’,’custemail’: ’email@domain.com’} response = requests.post(“http://httpbin.org/post”,data=data_dictionary) # we then print out the http status_code print(“HTTP Status Code: ” + str(response.status_code)) if response.status_code == 200: print(response.text) $python3 form_post_method.py HTTP Status Code: 200 { “args”: {}, “data”: “”, “files”: {}, “form”: { “custemail”: “email@domain.com”, “custname”: “customer”, […]

  • Program to do digest authentication using requests module

    $cat digest_authentication.py #!/usr/bin/env python3 import requests from requests.auth import HTTPDigestAuth url = ‘http://httpbin.org/digest-auth/auth/user/pass’ response = requests.get(url, auth=HTTPDigestAuth(‘user’, ‘pass’)) print(‘Response.status_code:’+ str(response.status_code)) if response.status_code == 200: print(‘Login successful :’+str(response.json())) $ $python3 digest_authentication.py Response.status_code:200 Login successful :{‘authenticated’: True, ‘user’: ‘user’}

  • Program to do basic authentication using “requests” module in python

    $python3 basic_authentication.py Response.status_code:401 $cat basic_authentication.py #!/usr/bin/env python3 import requests from requests.auth import HTTPBasicAuth requests.get(‘https://api.github.com/user’, auth=HTTPBasicAuth(‘user’, ‘password’)) # requests provides a shorthand for this authentication method response = requests.get(‘https://api.github.com/user’, auth=(‘user’, ‘password’)) print(‘Response.status_code:’+ str(response.status_code)) if response.status_code == 200: print(‘Login successful :’+response.text) $