乐闻世界logo
搜索文章和话题

How to create a database from shell command in MySQL?

1个答案

1

Creating a database in MySQL using shell commands typically involves accessing the system's command-line interface to execute MySQL commands. Below are the specific steps and examples:

  1. Open the command-line tool:

    • On Windows, use cmd or PowerShell.
    • On Linux or Mac OS, open Terminal.
  2. Log in to the MySQL server:

    • Use the mysql command-line tool to log in to the MySQL server. The format is as follows:
      shell
      mysql -u username -p
    • Here, username is your MySQL username. After executing the command, the system will prompt you to enter your password.
  3. Create the database:

    • Once logged in, you will be in the MySQL command-line interface where you can create the database:
      shell
      CREATE DATABASE database_name;
    • For example, to create a database named SampleDB, you would input:
      shell
      CREATE DATABASE SampleDB;
  4. Exit the MySQL command-line interface:

    • After creating the database, you can exit the MySQL command-line interface with:
      shell
      EXIT;

Example

Assume your username is root, and you want to create a database named TestDB. The following are the specific steps in the command-line:

bash
# Open the terminal or command-line window # Log in to MySQL mysql -u root -p # Enter your password # Create the database CREATE DATABASE TestDB; # Exit MySQL EXIT;

By following these steps, you can successfully create a database in MySQL using the command-line. This method is particularly useful for managing databases via scripts or in environments without a graphical interface.

2024年8月7日 09:41 回复

你的答案