Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In MySQL is there a variable for the current database?

I have a script that I run on multiple databases and to run on multiple databases I just change the MySql "USE" statement.

I'm wanting to have a select statement that outputs the current database the script is executing against as a field.

For example:


USE my_db;

SELECT 
  CURRENT_DB, -- this is where to insert the current executing db, i.e. "my_db"
  id, name, blah, blah
FROM my_table

like image 499
thames Avatar asked Sep 02 '25 15:09

thames


1 Answers

Use the database() function: http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_database

like image 92
dcp Avatar answered Sep 05 '25 04:09

dcp