What do you mean by default MySQL database for the user?

MySQLMySQLi Database

Actually, there is no default database for the user. But we have default database for the current session. It can be seen from the following query −

mysql> Select Database();
+------------+
| Database() |
+------------+
| sample     |
+------------+
1 row in set (0.00 sec)

The above result set shows that we are using ‘sample’ database currently. It is set for the current session. We can set another database, with the help of USE statement, also for the current session as follows −

mysql> USE query;
Database changed

mysql> Select Database();
+------------+
| Database() |
+------------+
| query      |
+------------+
1 row in set (0.00 sec)

Now, ‘query’ would be the default database for the current session.

Published on 19-Feb-2018 12:05:53