0% found this document useful (0 votes)
6 views

2-SQL_BASIC-GUIDE-BEGINNER-1

This guide provides a comprehensive overview of using MySQL with XAMPP through shell commands, catering to both beginners and experienced users. It covers installation, accessing the MySQL shell, common commands, and database management, along with practical examples and beginner-friendly tasks. The document emphasizes the advantages of using shell commands for greater control, flexibility, and automation in database management.

Uploaded by

jayjayjala1103
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

2-SQL_BASIC-GUIDE-BEGINNER-1

This guide provides a comprehensive overview of using MySQL with XAMPP through shell commands, catering to both beginners and experienced users. It covers installation, accessing the MySQL shell, common commands, and database management, along with practical examples and beginner-friendly tasks. The document emphasizes the advantages of using shell commands for greater control, flexibility, and automation in database management.

Uploaded by

jayjayjala1103
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

A Comprehensive Guide to XAMPP MySQL Using Shell Commands

This guide is designed to help you navigate MySQL in XAMPP using shell
commands. Whether you're a beginner or have some experience with
databases, this step-by-step guide will walk you through the essentials.

Table of Contents

1. Introduction to XAMPP and MySQL

2. Installing and Setting Up XAMPP

3. Accessing the MySQL Shell

4. Common MySQL Shell Commands

5. Creating and Managing Databases

6. All Queries: Definitions, Examples, and Usage

7. Working with Tables

8. Importing and Exporting Data

9. Managing Users and Permissions

10. Beginner-Friendly Tasks

11. Troubleshooting Common Issues

12. Conclusion and Best Practices

1. Introduction to XAMPP and MySQL

XAMPP is an open-source web server solution that includes Apache, MySQL


(MariaDB), PHP, and Perl. MySQL is a powerful database management
system used for storing and managing data for web applications.

Why use the shell for MySQL?

● Greater control and flexibility.

● Faster execution of commands compared to GUI tools.

● Ideal for automation and scripting.


2. Installing and Setting Up XAMPP

1. Download XAMPP

o Visit the official XAMPP website.

o Download the version compatible with your operating system


(Windows, macOS, or Linux).

2. Install XAMPP

o Run the installer and follow the on-screen instructions.

o Choose components: Ensure "MySQL" is selected.

3. Start XAMPP Control Panel

o Open the XAMPP Control Panel.

o Start the "Apache" and "MySQL" modules.

4. Verify Installation

o Open a web browser and navigate to


http://localhost/phpmyadmin.

o If the page loads, XAMPP and MySQL are properly installed.

3. Accessing the MySQL Shell

Step-by-Step Guide to Access the MySQL Shell

1. Open the Shell

o Launch the XAMPP Control Panel.

o Click the "Shell" button. This opens a command-line interface


where you can interact with MySQL and other tools.

2. Log into MySQL

o Type the following command and press Enter:

o mysql -u root -p

o The -u root specifies the username (default is root in XAMPP).


o The -p flag indicates that a password is required. By default,
XAMPP sets no password for the root user, so press Enter if
prompted for a password.

3. Confirm Access

o After logging in successfully, you will see the mysql> prompt,


which means you are now in the MySQL shell and can execute
commands.

4. Exit the Shell

o When you're done, type:

o EXIT;

o This will safely log you out of the MySQL shell.

Tip: If you encounter issues, ensure MySQL is running in the XAMPP Control
Panel.

4. Common MySQL Shell Commands

Learning a few basic commands will help you navigate and manage your
databases effectively. Below is a list of commonly used MySQL commands
with explanations:

Command Description

SHOW DATABASES; Lists all available databases.

CREATE DATABASE Creates a new database named


dbname; dbname.

USE dbname; Switches to the specified database.

Lists all tables in the current


SHOW TABLES;
database.

Displays the structure of the


DESCRIBE tablename;
specified table.

EXIT; Exits the MySQL shell.

Detailed Examples

1. Show All Databases


To see all available databases:

SHOW DATABASES;

Output will list all databases like this:

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| sys |

+--------------------+

2. Create a New Database

To create a new database called test_db:

CREATE DATABASE test_db;

You should see a message like:

Query OK, 1 row affected (0.01 sec)

3. Use a Database

To start working in a specific database (e.g., test_db):

USE test_db;

Output:

Database changed

4. Exit the Shell

To exit the MySQL shell:

EXIT;

5. Creating and Managing Databases


Creating and managing databases is one of the primary tasks when working
with MySQL. Below are detailed steps:

Creating a New Database

1. Command to Create a Database

o To create a database named my_database, use:

o CREATE DATABASE my_database;

o A successful response will look like this:

o Query OK, 1 row affected (0.02 sec)

2. Verify the Database

o Check if your database was created:

o SHOW DATABASES;

o You should see my_database in the list.

Selecting a Database

1. Switch to Your Database

o Use the USE command to select your database:

o USE my_database;

o Output:

o Database changed

2. Why Select a Database?

o Once selected, all subsequent commands will be executed within


this database.

Deleting a Database

1. Command to Drop a Database

o To delete a database named my_database:

o DROP DATABASE my_database;

o A confirmation message will appear:

o Query OK, 0 rows affected (0.01 sec)


2. Important Note:

o Be cautious when using the DROP command as it permanently


deletes the database and all its data.

6. All Queries: Definitions, Examples, and Usage

This section covers commonly used MySQL queries, their purposes, and
detailed examples to help you master their usage.

Query: SELECT

Purpose: Retrieve data from one or more tables.

SELECT column1, column2 FROM table_name;

Example:

SELECT name, age FROM students;

Output:

+--------+-----+

| name | age |

+--------+-----+

| John | 20 |

| Alice | 22 |

+--------+-----+

Query: INSERT

Purpose: Insert new data into a table.

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

Example:

INSERT INTO students (name, age) VALUES ('Bob', 25);

Output:

Query OK, 1 row affected (0.01 sec)

Query: UPDATE
Purpose: Update existing data in a table.

UPDATE table_name SET column1 = value1 WHERE condition;

Example:

UPDATE students SET age = 23 WHERE name = 'Alice';

Output:

Query OK, 1 row affected (0.01 sec)

Query: DELETE

Purpose: Remove data from a table.

DELETE FROM table_name WHERE condition;

Example:

DELETE FROM students WHERE name = 'Bob';

Output:

Query OK, 1 row affected (0.01 sec)

Query: CREATE TABLE

Purpose: Create a new table.

CREATE TABLE table_name (

column1 datatype,

column2 datatype

);

Example:

CREATE TABLE students (

id INT AUTO_INCREMENT PRIMARY KEY,

name VARCHAR(100),

age INT

);

Output:

Query OK, 0 rows affected (0.05 sec)


Query: DROP TABLE

Purpose: Delete an entire table.

DROP TABLE table_name;

Example:

DROP TABLE students;

Output:

Query OK, 0 rows affected (0.03 sec)

10. Beginner-Friendly Tasks

Here are 10 beginner-friendly tasks to practice MySQL commands and


develop your skills:

1. Create a Database

o Task: Create a database named school.

o Command:

o CREATE DATABASE school;

2. Create a Table

o Task: Inside the school database, create a table named students


with columns id, name, and age.

o Command:

o CREATE TABLE students (

o id INT AUTO_INCREMENT PRIMARY KEY,

o name VARCHAR(50),

o age INT

o );

3. Insert Data

o Task: Add three students to the students table.

o Command:
o INSERT INTO students (name, age) VALUES ('John', 20), ('Alice',
22), ('Bob', 25);

4. Retrieve Data

o Task: Display all students in the students table.

o Command:

o SELECT * FROM students;

5. Filter Data

o Task: Retrieve students older than 21.

o Command:

o SELECT * FROM students WHERE age > 21;

6. Update Data

o Task: Change Alice's age to 23.

o Command:

o UPDATE students SET age = 23 WHERE name = 'Alice';

7. Delete Data

o Task: Remove Bob from the students table.

o Command:

o DELETE FROM students WHERE name = 'Bob';

You might also like