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

mysql-commands

This document provides a step-by-step guide for connecting to a MySQL database and performing various operations such as listing databases, creating and modifying tables, inserting, updating, and deleting data. It includes specific SQL commands for each operation, making it a useful reference for database management. Key commands include connecting to the database, creating databases and tables, and manipulating data within those tables.

Uploaded by

riteshbarik3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

mysql-commands

This document provides a step-by-step guide for connecting to a MySQL database and performing various operations such as listing databases, creating and modifying tables, inserting, updating, and deleting data. It includes specific SQL commands for each operation, making it a useful reference for database management. Key commands include connecting to the database, creating databases and tables, and manipulating data within those tables.

Uploaded by

riteshbarik3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SQL

1. Connect to MySQL

To connect to a MySQL database from the command line:

bash

Copy code

mysql -h <RDS-endpoint> -u <username> -p

<RDS-endpoint>: Replace with your RDS instance endpoint (e.g.,


mydbinstance.xxxxxxxxxxx.us-west-2.rds.amazonaws.com).
<username>: Your MySQL username (e.g., admin).
After typing the command, it will ask for your password.

2. List Databases

To see all the databases on the MySQL server:

SHOW DATABASES;

3. Create a Database

To create a new database:

CREATE DATABASE mydatabase;

4. Select a Database

To use a specific database:

USE mydatabase;

5. Create a Table

To create a table within a selected database:

CREATE TABLE customers (


id INT AUTO_INCREMENT PRIMARY KEY,

name VARCHAR(100),

email VARCHAR(100) UNIQUE,

created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP

);

6. Show Tables

To list all tables in the current database:

SHOW TABLES;

7. Describe a Table

To see the structure (schema) of a specific table:

DESCRIBE customers;

8. Insert Data into a Table

To insert data into a table:

INSERT INTO customers (name, email)

VALUES ('John Doe', 'john.doe@example.com');

9. Select Data from a Table

To select and view data from a table:

SELECT * FROM customers;

10. Update Data in a Table

To update existing records in a table:


UPDATE customers

SET email = 'john.newemail@example.com'

WHERE name = 'John Doe';

11. Delete Data from a Table

To delete records from a table:

DELETE FROM customers

WHERE name = 'John Doe';

12. Drop a Table

To delete a table and its data permanently:

DROP TABLE customers;

13. Drop a Database

To delete a database and all of its contents:

DROP DATABASE mydatabase;

14. Alter Table (Modify Table Structure)

To add a new column to an existing table:

ALTER TABLE customers

ADD phone_number VARCHAR(20);

To modify an existing column's data type:

ALTER TABLE customers

MODIFY email VARCHAR(255);


To delete a column:

ALTER TABLE customers

DROP COLUMN phone_number;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy