How to deselect database in MySQL

If you have already installed a PostgreSQL database, you may skip these steps. Both databases are not required.

For a list of supported MySQL databases, see Supported NiFi Registry databases.

  1. Log in to the node on which you want to install NiFi Registry.
  2. Install MySQL and the MySQL community server, and start the MySQL service:

    yum localinstall \
    https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
    
    yum install mysql-community-server
    
    systemctl start mysqld.service

  3. Obtain the randomly generated MySQL root password:

    grep 'A temporary password is generated for root@localhost' \
    /var/log/mysqld.log |tail -1

  4. Reset the MySQL root password. Enter the following command. You are prompted for the password you obtained in the previous step. MySQL then asks you to change the password:

    Once you get connected with the MySQL server, it is required to select a database to work with. This is because there might be more than one database available with the MySQL Server.

    Selecting MySQL Database from the Command Prompt

    It is very simple to select a database from the mysql> prompt. You can use the SQL command use to select a database.

    Example

    Here is an example to select a database called TUTORIALS −

    [root@host]# mysql -u root -p
    Enter password:******
    mysql> use TUTORIALS;
    Database changed
    mysql> 
    

    Now, you have selected the TUTORIALS database and all the subsequent operations will be performed on the TUTORIALS database.

    NOTE − All the database names, table names, table fields name are case sensitive. So you would have to use the proper names while giving any SQL command.

    Selecting a MySQL Database Using PHP Script

    PHP uses mysqli_select_db function to select the database on which queries are to be performed. This function takes two parameters and returns TRUE on success or FALSE on failure.

    Summary: in this tutorial, you will learn how to select a database in the 

    Enter password:

    Code language: Shell Session (shell)
    7 program and MySQL Workbench by using the

    Enter password:

    Code language: Shell Session (shell)
    8 statement.

    Selecting a MySQL database using the mysql client tool

    When you log in to a MySQL database server using the

    Enter password:

    Code language: Shell Session (shell)
    7 client tool without specifying a database name, MySQL server will set the current database to NULL.

    First, log in to MySQL using the

    SELECT database();

    Code language: SQL (Structured Query Language) (sql)
    0 user account:

    mysql -u root -p

    Code language: SQL (Structured Query Language) (sql)

    MySQL will prompt you for a password:

    Enter password:

    Code language: Shell Session (shell)

    To log in, you need to provide the correct password of the

    SELECT database();

    Code language: SQL (Structured Query Language) (sql)
    0 user account and press

    SELECT database();

    Code language: SQL (Structured Query Language) (sql)
    2. To display the current database, you use the following statement:

    SELECT database();

    Code language: SQL (Structured Query Language) (sql)

    It’ll return the following:

    +------------+ | database() | +------------+ | NULL | +------------+ 1 row in set (0.00 sec)

    Code language: Shell Session (shell)

    It means the current database is not set. If you issue a statement, MySQL will issue an error. For example:

    SELECT * FROM t;

    Code language: SQL (Structured Query Language) (sql)

    Error:

    ERROR 1046 (3D000): No database selected

    Code language: plaintext (plaintext)

    To select a database to work with, you use the

    Enter password:

    Code language: Shell Session (shell)
    8 statement:

    USE database_name;

    Code language: SQL (Structured Query Language) (sql)

    For example, the following statement uses the USE statement to set the current database to classicmodels:

    USE classicmodels;

    Code language: SQL (Structured Query Language) (sql)

    If you see the following message, it means that you have changed the database to

    SELECT database();

    Code language: SQL (Structured Query Language) (sql)
    4 successfully:

    Database changed

    Code language: Shell Session (shell)

    To verify it, you can use the select database() statement:

    SELECT database();

    Code language: SQL (Structured Query Language) (sql)

    It’ll return something like:

    Enter password:

    Code language: Shell Session (shell)
    0

    If the classicmodels database doesn’t exist, you’ll get the following error after executing the

    Enter password:

    Code language: Shell Session (shell)
    8 statement:

    Enter password:

    Code language: Shell Session (shell)
    1

    In this case, you need to find which databases are available on your server by using the show databases statement:

    Enter password:

    Code language: Shell Session (shell)
    2

    The output may look like the following:

    Enter password:

    Code language: Shell Session (shell)
    3

    Selecting a database when you login

    If you know which database you want to work with before you log in, you can use the

    SELECT database();

    Code language: SQL (Structured Query Language) (sql)
    6 flag. For example, the following command connects to the

    SELECT database();

    Code language: SQL (Structured Query Language) (sql)
    4 database with the user account

    SELECT database();

    Code language: SQL (Structured Query Language) (sql)
    0:

    Enter password:

    Code language: Shell Session (shell)
    4

    In this command, we specify the database

    SELECT database();

    Code language: SQL (Structured Query Language) (sql)
    4 after the

    SELECT database();

    Code language: SQL (Structured Query Language) (sql)
    6 flag.

    After entering the password and logging in successfully, you can check the current database:

    SELECT database();

    Code language: SQL (Structured Query Language) (sql)

    Output:

    Enter password:

    Code language: Shell Session (shell)
    0

    Selecting a database in MySQL Workbench

    If you connect to a MySQL Server via the MySQL Workbench application, you can select a database when you create the database connection as shown in the following screenshot:

    How to deselect database in MySQL
    How to deselect database in MySQL

    Once logged in, you can select another database by issuing the

    Enter password:

    Code language: Shell Session (shell)
    8 statement or use the

    +------------+ | database() | +------------+ | NULL | +------------+ 1 row in set (0.00 sec)

    Code language: Shell Session (shell)
    2 feature provided by MySQL Workbench:

    How to deselect database in MySQL
    How to deselect database in MySQL

    In this tutorial, you have learned various ways to select a MySQL database via the

    Enter password:

    Code language: Shell Session (shell)
    7 program and MySQL Workbench application.

    How to unselect a database in MySQL?

    It goes like: CREATE DATABASE foofoofooweird; USE foofoofooweird; DROP DATABASE foofoofooweird; Et voila, no database is in use.

    How to unselect a schema in MySQL?

    From the home screen, right-click on a MySQL connection, choose Edit Connection, and set the desired default schema on the Default Schema box. The selected schema is displayed as bold in the schema navigator. Filter to This Schema: Enables you to target specific schemas in the list.

    How do I get out of database?

    Type \q to exit the mysql program. Type the user's password, and then press Enter.

    How do I switch databases in MySQL?

    You have to indicate it with the USE command. The USE command is also used when you have more than one database on a MySQL server and need to switch between them. You must choose the correct database each time you start a MySQL session.