Ticker

6/recent/ticker-posts

What Is Mysql and How to use Some of the most commonly used MySQL commands

 


MySQL is a popular open-source relational database management system that is widely used for web applications. It was created in 1995 by Swedish developers Michael Widenius and David Axmark, and is now owned by Oracle Corporation. MySQL is often used in conjunction with other popular web development technologies like PHP, Python, and Ruby on Rails.

Relational databases like MySQL are used to store and manage structured data. They consist of one or more tables, each of which has a set of columns and rows. Each column represents a different type of data (such as a string or integer), while each row represents a single record or entry in the table.

One of the key features of MySQL is its support for SQL (Structured Query Language), a standardized language used to interact with relational databases. SQL allows you to perform a wide variety of operations on your MySQL databases, such as creating tables, inserting data, updating data, and querying data.

Here are some basic MySQL concepts and commands to get you started:

Creating a database

Before you can create tables or insert data, you need to create a database to hold your data. To create a new database in MySQL, you can use the CREATE DATABASE command:
CREATE DATABASE mydatabase;
 To create a new table in MySQL, you can use the CREATE TABLE command:


CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    email VARCHAR(255) NOT NULL,
    age INT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
This will create a new table called "users" with five columns: id, name, email, age, and created_at. The id column is set as the primary key, which means it uniquely identifies each row in the table. The AUTO_INCREMENT keyword tells MySQL to automatically generate a new value for id for each new row added to the table. The NOT NULL keyword means that the name and email columns cannot be empty.

Inserting data
Once you have a table, you can insert data into it using the INSERT INTO command:
INSERT INTO users (name, email, age) VALUES ('John', 'john@example.com', 25);
This will insert a new row into the "users" table with the values "Niraj" for name, "niraj@example.com" for email, and 25 for roll.

Querying data
To retrieve data from a table, you can use the SELECT command:

SELECT * FROM users;
This will retrieve all rows from the "users" table. You can also filter and sort the results using various SQL keywords and operators, such as WHERE, AND, OR, ORDER BY, and LIMIT.

Updating data
To update existing data in a table, you can use the UPDATE command:

UPDATE users SET roll = 30 WHERE id = 1;
This will update the age column of the row with id 1 to 30.

Deleting data
To delete rows from a table, you can use the DELETE command:

DELETE FROM users WHERE roll < 20;
This will delete all rows from the "users" table where the roll column is less than 20


Post a Comment

0 Comments