How do I set the default schema for a user in MySQL

Robert Louis Murphy picture Robert Louis Murphy · Sep 14, 2012 · Viewed 113.4k times · Source

Is there a way to set a default schema for each user in MySQL and if so how? Where user x would default to schema y and user z would default to schema a.

Answer

Devart picture Devart · Sep 14, 2012

There is no default database for user. There is default database for current session.

You can get it using DATABASE() function -

SELECT DATABASE();

And you can set it using USE statement -

USE database1;

You should set it manually - USE db_name, or in the connection string.