This is a limitation in MySQL:
The DEFAULT value clause in a data type specification indicates a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression
But @@ and @ are expressions that are used to get values ββfor system or local variables. And they are not permanent. They can be changed at runtime.
Your approach is great, but if you really want to use a system variable, you can use dynamic SQL, for example:
set @q = concat('alter table t1 add column time_zone char(64) not null default ', quote(@@system_time_zone)); prepare stmt from @q; execute stmt; deallocate prepare stmt;
In @lanzz's tip: In the last code block, @@system_time_zone becomes a constant instead of constant variables. And if the time zone is changed in the future, the default value for this column will remain unchanged.
source share