Is it possible to use variables in MySQL schema definition? I need to do something like this:

use mydb;
SET @DBNAME = 'users';
CREATE TABLE `some_table` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`) USING BTREE,
  CONSTRAINT `key_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES @DBNAME.`users` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
);


REFERENCES @DBNAME.users - is the part I'm interested in.

Is it possible to somehow parametrize DB name in schema definition?

Thanks!
You cannot use variables for object names. What you can do is compose the statement string dynamically and PREPARE then EXECUTE it.

SET @DBNAME = 'users';
SET @STMT = CONCAT(
'CREATE TABLE `some_table` (',
'  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,',
'  `user_id` bigint(20) unsigned DEFAULT NULL,',
'  PRIMARY KEY (`id`),',
'  KEY `user_id` (`user_id`) USING BTREE,',
'  CONSTRAINT `key_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES ', @DBNAME, '.`users` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION'
);
PREPARE s1 FROM @STMT;
EXECUTE s1;