0

I am trying create a database in mysql database from separate .sql file and passing database name as variable.I am creating database from file to create tenant (separate database) and insert credentials to the Credentials table.

select @name := 'xxxxxx'; //admin will enter name here
create database @name;//here it is not creating a database

1 Answer 1

2

You need to have sql prepared statements to use dynamic queries. Also the user need to have authorization to create new database in the server.

use test;
set @name = 'abc';
set @statment= CONCAT('create database ', @name);
PREPARE stmt1 from @statment;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;

Refer: Mysql Prepare Statement

Sign up to request clarification or add additional context in comments.

1 Comment

tq @balakrishnan

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.