mysqladmin Create Database

Summary: in this tutorial, you will learn how to use mysqladmin create database command to create a new database in a MySQL server.

mysqladmin is a client tool that allows you to perform database administrative tasks. You can use the mysqladmin to create a new database in a MySQL server.

Here’s the basic syntax for creating a new database using the mysqladmin:

mysqladmin [options] create db_name;Code language: CSS (css)

In this syntax:

  • mysqladmin: invoke the mysqladmin program.
  • [options]: specify the connection details to a MySQL server including hostname, username, and password.
  • create: instruct mysqladmin to create a new database.
  • db_name: specify the name of the database that you want to create.

We’ll show you how to create a test database on the local MySQL server.

First, open the Command Prompt on Windows or Terminal on Unix-like systems.

Second, create the test database using the mysqladmin client tool:

mysqladmin -u root -p create test;

It’ll prompt you to enter a password for the root user account. After entering the valid password, it’ll create a database called test.

Behind the scenes, the mysqladmin uses the CREATE DATABASE statement to create a new database. If the test database already exists, it’ll display an error message:

mysqladmin: CREATE DATABASE failed; error: 'Can't create database 'test'; database exists'Code language: JavaScript (javascript)

To create a database without providing the username and password, you need to set up a login path using the mysql_config_editor program.

If you have done so, you can create a database using the following command without providing the connection details:

mysqladmin create sampledb;

Notice that you should not use the password directly after the –password option, because it is not secure.

mysqladmin -u root --password=YourPassword create test1;

Warning:

mysqladmin: [Warning] Using a password on the command line interface can be insecure.Code language: CSS (css)

Summary

  • Use the mysqladmin [options] create db_name command to create a new database using the mysqladmin program.
Was this tutorial helpful?