Skip to main content

Practical 1: Getting Started with MYSQL


 Getting Started with MySQL

  1. Introduction to MySQL
    • Definition: MySQL is an open-source relational database management system (RDBMS)
    • Uses: Web applications, data warehousing, e-commerce, logging applications
    • Key features: Speed, reliability, scalability, and ease of use
  2. Installing MySQL
    • Download MySQL Community Server from official website
    • Follow installation wizard for your operating system
    • Set root password during installation
    • Verify installation:
      mysql --version
  3. MySQL Command-line Client
    • Accessing MySQL:
      mysql -u root -p
    • Basic commands:

      SHOW
      DATABASES; CREATE DATABASE mydb; USE mydb; SHOW TABLES;
  4. MySQL Workbench
    • Introduction: Visual tool for database design and management
    • Key features:
      • SQL development
      • Data modeling
      • Server administration
    • Example: Creating a new connection
      • New Connection > Enter details (hostname, username, password)
  5. PHPMyAdmin
    • Web-based MySQL administration tool
    • Often comes pre-installed with web hosting packages
    • Key features:
      • Manage databases, tables, columns, relations, indexes, users, permissions
      • Execute SQL statements
      • Import/export data in various formats
    • Accessing PHPMyAdmin:
  6. Creating Your First Database and Table Using command-line:

    CREATE
    DATABASE bookstore; USE bookstore; CREATE TABLE books ( id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(100) NOT NULL, author VARCHAR(100) NOT NULL, publication_year INT, isbn VARCHAR(13) UNIQUE );
    Using PHPMyAdmin:
    • Click "New" to create a database
    • Enter database name and click "Create"
    • Click on the new database
    • Click "Create table", enter name and number of columns
    • Fill in column details and click "Save"
  7. Inserting and Querying Data Inserting data:

    INSERT
    INTO books (title, author, publication_year, isbn) VALUES ('To Kill a Mockingbird', 'Harper Lee', 1960, '9780446310789');
    Querying data:

    SELECT * FROM books; SELECT title, author FROM books WHERE publication_year > 1950;


Basic Commands everyone should know:

The following commands are particularly useful for navigating the MySQL environment, managing your session, and controlling how results are displayed. They can significantly improve your efficiency when working with MySQL from the command line.

  1. ? or \h (help) Displays the help menu, showing available commands and their descriptions.
  2. \c (clear) Clears the current input statement, useful if you make a mistake and want to start over.
  3. \r (connect) Reconnects to the MySQL server. You can optionally specify a database and host.
  4. \d (delimiter) Sets a new statement delimiter. Useful when writing stored procedures or functions.
  5. \G (ego) Sends the command to the MySQL server and displays the result vertically, which can be more readable for wide result sets.
  6. \q (quit/exit) Exits the MySQL client.
  7. \g (go) Sends the current command to the MySQL server for execution.
  8. \n (nopager) Disables the pager and prints output directly to stdout.
  9. \P (pager) Sets a pager for output. Useful for viewing large result sets.
  10. . (source) Executes an SQL script file. You need to provide the file name as an argument.
  11. \s (status) Retrieves and displays status information from the server.
  12. ! (system) Allows you to execute a system shell command without leaving the MySQL client.
  13. \u (use) Switches to another database. You need to provide the database name as an argument.
  14. \C (charset) Switches to another character set. This can be necessary when processing binary logs with multi-byte character sets.
  15. \W (warnings) Enables the display of warnings after every statement.
  16. \w (nowarning) Disables the display of warnings after every statement.


Exercises:

  1. Installation and Setup
    • Install MySQL on your computer
    • Create a new user with username 'student' and password 'password123'
    • Grant this user all privileges on a new database called 'school'
  2. Database and Table Creation
    • Create a database named 'library'
    • In this database, create a table named 'authors' with the following columns:
      • id (integer, auto-increment, primary key)
      • name (varchar, maximum 100 characters, not null)
      • birth_year (integer)
      • nationality (varchar, maximum 50 characters)
  3. Data Manipulation
    • Insert at least 5 authors into the 'authors' table
    • Write a query to select all authors born after 1950
    • Update the nationality of one author
    • Delete an author from the table
  4. PHPMyAdmin Practice
    • Log into PHPMyAdmin
    • Create a new database called 'inventory'
    • Create a table named 'products' with columns: id, name, price, and quantity
    • Insert 3 products using the PHPMyAdmin interface
    • Use the SQL tab to write a query that selects all products with a price greater than 10
  5. MySQL Workbench
    • Create a new connection in MySQL Workbench
    • Design an Entity-Relationship Diagram (ERD) for a simple blog system with tables for posts, users, and comments
    • Forward engineer this design to create the actual database and tables

Comments

Popular posts from this blog

Python OOPs Concepts: Using Variables and Methods

  Types of Variables in OOPs Python   Instance Variable Static Variable Local Variable   Object Level Variables Class Level Variables Method Level Variables When to use: For Every Object if you want Separate copy, use Instance Variables For all object one copy is required, use static variables Inside method, Just used for temporary requirement Where to Declare Inside the constructor method (in general) Within the class directly, outside of methods (in general)   Within the method only. How to Declare Within the constructor: Instance variables can be declared within the constructor method using the self .   Using default values : Instance variables can be assigned default values during initialization.   Outside the class: use object name.   ·          Within the class directly

Is Li-Fi Better than Wi-Fi?

Li-Fi  ( light fidelity )  is a bidirectional wireless system that transmit data to the devices like mobiles, laptop, etc., via infrared light or LED. The device has a receiver to pick up light signals and a transmitter to send light signal back to the lamp using infrared light or LED. It was first unveiled in 2011 and, unlike Wi-Fi, which uses radio frequency, Li-Fi technology only needs a light source with a chip to transmit an internet signal through light waves. Light fidelity (LiFi) is a faster, more secure and efficient wireless connection that uses light waves to transmit data Li-Fi technology still has a long way to go before worldwide adoption but every year, we are getting nearer to enjoying it for ourselves. The future surely looks bright with LiFi. How LiFi Works? LiFi makes use of visible light through overhead lighting for the transmission of data. This is possible through the use of a Visible Light Communications (VLC) system for data transmission. A VLC system has two q

Polymorphism: Method Overloading vs Method Overriding

  Method Overloading In object-oriented programming languages, method overloading enables a class to have several methods with the same name but different parameters. However, in Python, method overloading is not directly supported as opposed to languages such as Java or C++. This is because Python allows developers to define default arguments for their methods and pass arguments of any type to a method. This flexibility allows a single method to handle various types of arguments, eliminating the need for overloading.   However, there is a way to simulate method overloading in Python by using default argument values or variable length arguments and conditional statements. Here's an example: Program using default arguments:       Program using variable length arguments:   Multiple methods with Same Name: When we define multiple methods with same name, Python will consider the last defined method only. Python will not support method overloading. ( Why? Method overlo