Creating and Selecting a MySQL Database

MySQLMySQLi Database

Creating a Database

A database can be created using the below statement −

CREATE DATABASE databaseName;

Example

CREATE DATABASE STUDENT

Selecting a MySQL Database

If we wish to access and use a specific database, we can use the following query −

Query

mysql> USE databaseName
Database changed

Example

USE STUDENT

The ‘USE’ statement doesn’t require a semi-colon. This is similar to the ‘QUIT’ statement. Even if semi-colon is used, it does no harm.

We can create and use a database of our own, but before that, MySQL administrator’s permission is required.

The MySQL administrator can execute a command as shown below to provide permissions −

mysql> GRANT ALL ON tableName.* TO ‘your_mysql_name’@’your_client_host’;

Here, ‘your_mysql_name’ refers to the MySQL user name which is assigned to the user.

The ‘your_client_host’ refers to the host from which the user connected to the server.

raja
Published on 08-Mar-2021 12:23:54
Advertisements