CodeSteps

Python, C, C++, C#, PowerShell, Android, Visual C++, Java ...

How to Create a MySQL database from command line?

MySQL provides command line tools to create databases and managing them. In this article we are going to discuss on creating a database from command line.

Step 1. First we need to connect to the MySQL database server. Type the below command at command line to connect to the server:

mysql -hMyServerName -uMyUserName -pMyPassword

Here MyServerName is the IP address or full name of the server where MySQL database server installed. MyUserName is the username to connect to the database server. MyPassword is the user password to connect to the database server.

To connect from the server where MySQL database server installed, no need to pass “-hMyServerName” option; for remote connections, this is must.

Step 2. Once connected to MySQL database server, MySQL will display “mysql>” command prompt to allow us to type MySQL commands.

Type the below command at “mysql>” prompt to create the database:

mysql> CREATE DATABASE MyDatabaseName;

Here MyDatabaseName is the name of the database to create. If database prefix is required, we must provide database prefix along with the database name. For example: if the database prefix is “xyz_” and the database name is “Sample”, we need to pass “xyz_Sample” as the database name.

Step 3. Once the database is successfully created, MySQL allows to see list of databases currently available in the database server. Use below command to list all the available databases.

mysql> SHOW DATABASES;

Step 4. To use the database (To create tables, create users etc.,), we need to type the below command at “mysql>” command prompt. So, all commands we typed at command line are applicable to the current database.

mysql> USE MyDatabaseName;

Step 5. Once done with MySQL database operations, type “exit” command to disconnect from MySQL database server.

mysql> exit

<Mourya>

How to Create a MySQL database from command line?

Leave a Reply

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

Scroll to top