Activity 4: Research MySQL

Step 1: Research the Basics of MySQL

  • MySQL is a popular open-source Relational Database Management System (RDBMS). It's used to store, manage, and retrieve data efficiently.

  • Importance in Web Applications: MySQL is a cornerstone of many web applications, handling data for websites, online stores, social media platforms, and more. It allows web apps to store user information, product details, and other critical data.

  • Relational Database Management System (RDBMS): An RDBMS organizes data into tables, with relationships defined between them. This structure makes it easy to manage and query data efficiently.

    • Core Concepts:

      • Databases: A database is a collection of organized information. Think of it as a digital filing system.

      • Tables: Tables are the building blocks of a database. They have rows (representing individual records) and columns (representing data fields).

      • Columns: Columns define the types of information stored in a table (e.g., name, age, email).

      • Rows: Rows represent individual entries or records within a table (e.g., a specific user's information).

        Step 2: Understanding Databases and Tables

  • Databases:

    • Databases are designed to store and manage large amounts of data in a structured way. They ensure data integrity, consistency, and efficient retrieval.

    • Think of a database as a library with many books (tables) containing information (rows and columns).

  • Tables:

    • Tables are like spreadsheets with columns and rows.

    • Columns: Columns represent specific data fields (e.g., "Name," "Age," "City").

    • Rows: Rows represent individual records or entities (e.g., each person's information).

Step 3: Learn Basic MySQL Commands

  • Creating Databases:

    CREATE DATABASE database_name; (e.g., CREATE DATABASE my_website_data;

  • Creating Tables:

    CREATE TABLE table_name (column1 data_type, column2 data_type, ...);

    • Example:

CREATE TABLE users ( id INT PRIMARY KEY, username VARCHAR(255), email VARCHAR(255), password VARCHAR(255) );

  • Inserting Data:

    • INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);

    • Example:

INSERT INTO users (id, username, email, password) VALUES (1, 'john.doe', 'john.doe@example.com', 'password123');

  • Updating Data:

    UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;

  • Querying Data:

    SELECT column1, column2, ... FROM table_name WHERE condition;

    • Example:

      SELECT username, email FROM users WHERE id = 1;

  • Deleting Data:

    DELETE FROM table_name WHERE condition;

    • Example:

DELETE FROM users WHERE id = 1;

Step 4: Study Data Types in MySQL

  • Common Data Types:

    • INT: Stores whole numbers (e.g., 10, 25, -5).

    • VARCHAR: Stores variable-length strings of text (e.g., names, addresses).

    • DATE: Stores dates in the format YYYY-MM-DD (e.g., 2023-12-25).

    • TEXT: Stores large blocks of text (e.g., articles, blog posts).

  • Choosing the Right Data Type:

    • INT: Use for numeric values like IDs, ages, quantities.

    • VARCHAR: Use for text fields like names, addresses, descriptions.

    • DATE: Use for storing dates and times.

    • TEXT: Use for long text fields, but be aware it can impact performance.

Step 5: Explore MySQL Relationships

  • Relationships: Databases often have multiple tables that are related to each other.

  • Foreign Keys and Primary Keys:

    • Primary Key: A unique identifier for each row in a table (e.g., id in the users table).

    • Foreign Key: A column in one table that references the primary key in another table. It establishes the relationship between tables.

  • Types of Relationships:

    • One-to-One: One record in one table corresponds to exactly one record in another table.

    • One-to-Many: One record in one table can be related to multiple records in another table.

    • Many-to-Many: Multiple records in one table can be related to multiple records in another table.

Step 6: Research MySQL Indexing

  • Indexing: Indexing creates a "lookup table" for specific columns in a table. This speeds up data retrieval by allowing MySQL to quickly find the relevant rows.

  • Importance: Indexing improves database performance, especially for queries that involve searching or filtering data.

Step 7: Security in MySQL

  • User Privileges: MySQL allows you to create users with different levels of access to the database.

  • GRANT Command:

    GRANT privileges ON database_name.table_name TO user_name@host_name IDENTIFIED BY 'password';

    • Example:

GRANT SELECT, INSERT, UPDATE ON my_website_data.users TO john.doe@localhost IDENTIFIED BY 'password123';