Create a MySQL Database on Linux via Command Line

Setting up a MySQL database on Linux using the command line can seem intimidating, but it’s a fundamental skill for anyone working with databases. In this blog post, we will walk you through the steps to create a MySQL database on a Linux system using simple and easy-to-follow commands.

Steps to create a MySQL Database on Linux via Command Line

  1. Access MySQL Shell
  2. Create a New Database
  3. List All Databases
  4. Use the New Database
  5. Create Tables and Insert Data (Optional)

1. Access MySQL Shell

Before we can create a database, we need to access the MySQL shell. Open a terminal or command prompt and enter the following command, providing your MySQL root user password when prompted:

2. Create a New Database

Once you’re inside the MySQL shell, you can create a new database using the CREATE DATABASE command. Choose a name for your database and replace <database_name> with your desired name:

For example, to create a database named “mydb”, the command would be:

3. List All Databases

To verify that your new database has been created successfully, you can list all the databases using the following command:

This command will display a list of all databases, including the one you just created.

4. Use the New Database

To start using your newly created database, you need to select it using the USE command:

For instance, to use the “mydb” database, run:

5. Create Tables and Insert Data (Optional)

Once you have your database ready, you can create tables and start inserting data. This step is optional but essential for building your database’s structure and adding data to it. Use the CREATE TABLE and INSERT INTO commands to accomplish this.

Conclusion

Congratulations! You’ve successfully created a MySQL database on Linux using the command line. Understanding how to set up a database is a crucial skill for any developer or system administrator working with data-driven applications. By following these simple steps, you can quickly create and manage databases to support your projects.

Now that you have a new database, you can start building and storing data. Whether you’re working on a personal project or a large-scale application, databases are the backbone of data management. Happy coding!

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *