Wednesday, May 21, 2025

Learning ...Temp

 To set up MySQL in the XAMPP PHP environment with a database, users, and tables, follow these steps:


✅ Step 1: Start XAMPP Services

  1. Open XAMPP Control Panel.

  2. Start Apache and MySQL services.

  3. Click Admin next to MySQL to launch phpMyAdmin in your browser.


✅ Step 2: Create a Database in phpMyAdmin

  1. In phpMyAdmin, click "New" on the left sidebar.

  2. Under "Create database", enter a name (e.g., mydb) and choose collation like utf8mb4_general_ci.

  3. Click Create.


✅ Step 3: Create a User with a Password

  1. Go to the "User accounts" tab in phpMyAdmin.

  2. Click "Add user account".

  3. Enter:

    • Username: e.g., myuser

    • Host name: localhost

    • Password: your desired password

  4. Under Database for user, choose "Grant all privileges on database" and select your database (mydb).

  5. Scroll down and click Go.


✅ Step 4: Create Tables

  1. Click your database name (mydb) from the sidebar.

  2. Under "Create table", enter:

    • Table name: e.g., users

    • Number of columns: e.g., 3

  3. Click Go, then define columns like:

    • id – INT, Primary Key, AUTO_INCREMENT

    • username – VARCHAR(50)

    • email – VARCHAR(100)

  4. Click Save.


✅ Step 5: Connect to the Database in PHP (Optional)

If you're building a PHP app, here’s a sample connection script:

<?php
$servername = "localhost";
$username = "myuser";
$password = "yourpassword";
$dbname = "mydb";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

🧠 Tips

  • phpMyAdmin is a friendly GUI but you can also run raw SQL via the "SQL" tab.

  • For example, creating a user and database via SQL:

CREATE DATABASE mydb;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;

Let me know if you want a script to automatically generate users and tables, or want to do it via CLI.

No comments:

Post a Comment

SLSM Repository Proposal

A detailed proposal document for the "Self Learning Study Material (SLSM) Portal" for Tamil Nadu State , aligned with your vision...