Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从单独的.sql文件在mysql中创建数据库_Mysql_Database - Fatal编程技术网

从单独的.sql文件在mysql中创建数据库

从单独的.sql文件在mysql中创建数据库,mysql,database,Mysql,Database,我正在尝试从单独的.sql文件在mysql数据库中创建一个数据库,并将数据库名称作为变量传递。我正在从文件创建数据库以创建租户(单独的数据库),并将凭据插入凭据表 select @name := 'xxxxxx'; //admin will enter name here create database @name;//here it is not creating a database 您需要准备sql语句才能使用动态查询。用户还需要有在服务器中创建新数据库的权限 use test; set

我正在尝试从单独的.sql文件在mysql数据库中创建一个数据库,并将数据库名称作为变量传递。我正在从文件创建数据库以创建租户(单独的数据库),并将凭据插入凭据表

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

您需要准备sql语句才能使用动态查询。用户还需要有在服务器中创建新数据库的权限

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

请参阅:

您需要准备sql语句才能使用动态查询。用户还需要有在服务器中创建新数据库的权限

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

参考:

tq@Balakrishnatq@balakrishnan