How to create database in MySql ?
by Yogi P - December 4, 2022
Create database in MySql
To create a database in MySQL, you can use the following steps:
Open a MySQL command prompt. This can be done by logging in to your MySQL server and running the mysql command.
Use the CREATE DATABASE statement to create a new database. This statement should include the name of the database that you want to create, as well as any additional options or settings that you want to use. For example:
CREATE DATABASE my_database;
Use the USE statement to select the database that you just created. This will make the database the default database for any subsequent SQL queries that you run. For example:
USE my_database;
Use the CREATE TABLE statement to create tables in your database. This statement allows you to specify the structure of the table, including the names and data types of the columns, as well as any constraints or indexes that you want to apply. For example:
CREATE TABLE my_table (
id INT PRIMARY KEY AUTO_INCREMENT,
nameVARCHAR(255),
email VARCHAR(255)
);
Use the INSERT statement to insert data into your tables. This statement allows you to specify the values that you want to insert, as well as the columns where the data should be inserted. For example:
INSERT INTO my_table (name, email) VALUES ('Yogi Raj', 'yogi@example.com');
Use the SELECT statement to query your data. This statement allows you to specify the columns that you want to retrieve, as well as any conditions or filters that you want to apply. For example:
SELECT * FROM my_table WHERE name = 'Yogi Raj';
These are just a few examples of how to create a database and work with it in MySQL. There are many other commands and features that you can use to manage and query your data, and it is worth learning more about SQL and MySQL to fully understand their capabilities.