Creating a MySQL Database Using Command Line and MySQL Workbench

  • To create a database through MySQL command line and MySQL Workbench, follow these steps:
MySQL Command Line:
  • Open the MySQL command-line interface. You may need to provide your MySQL username and password to access the command line.
  • Once you're in the MySQL prompt, you can create a database using the `CREATE DATABASE` command. Here's the syntax:


    CREATE DATABASE database_name;

  • Replace `database_name` with the desired name for your new database. Make sure the name follows the rules for database identifiers (e.g., no spaces, special characters, etc.).
  • Execute the command by pressing Enter. The database will be created, and you'll receive a confirmation message.
  • Example:


    mysql> CREATE DATABASE my_database;
    Query OK, 1 row affected (0.01 sec)

MySQL Workbench:

  • Launch MySQL Workbench and connect to your MySQL server using your credentials.
  • Once connected, you'll see the "Navigator" pane on the left side. Under the "SCHEMAS" section, right-click and select "Create Schema..."
  • A new window will pop up. Enter the desired name for your database in the "Schema Name" field.
  • Optionally, you can also choose the default character set and collation for the database, or leave them as default.
  • Click the "Apply" button to create the database.
  • Example: In MySQL Workbench, the new database will appear under the "SCHEMAS" section in the Navigator.
  • Remember that creating a database will not automatically select it for use. To start working with the newly created database, you can use the `USE` command in the MySQL command-line interface, or you can select the database from the drop-down list in MySQL Workbench.
Using the database in MySQL Command Line:


    mysql> USE my_database;
    Database changed

  • Now, you can start creating tables and working with your newly created database.
Using the database in MySQL Workbench:
  • In MySQL Workbench, you can click on the newly created database in the "SCHEMAS" section to select it for use. Once selected, any queries or operations you perform will be applied to this database.

No comments:

Post a Comment