ALTER DATABASE
This page is part of MariaDB's Documentation.
The parent of this page is: SQL Statements for MariaDB Xpand
Topics on this page:
Overview
Modifies database characteristics, such as changing the default character-set and collation.
USAGE
Common Syntax:
ALTER {DATABASE | SCHEMA} <db_name>
[ [DEFAULT] COLLATE [=] <xpand_collation_name> ]
[ [DEFAULT] {CHARACTER SET | CHARSET} [=] <xpand_charset_name> ]
EXAMPLES
Change Character Set and Collation
Character sets define which characters can be used to store information in a database. A collation is a set of rules for sorting and comparing character sets, for example:
In a case-insensitive collation, "Sofia" and "sofia" would be considered the same name
In a case-sensitive collation, "Robert" and "robert" would be considered different names
If you do not specify a character set and collation for a database, the defaults will be used. The default character set and collation are determined by the character_set_server
and collation_server
system variables. If the system variables are not changed, the default character set is utf8
, and the default collation is utf8_general_ci
.
To change a character set and/or collation to be used as the default for all newly created tables within a database:
ALTER DATABASE db1
DEFAULT CHARACTER SET = 'utf8mb4'
DEFAULT COLLATE = 'utf8mb4_unicode_ci';
The DEFAULT
reserved word and equal sign (=
) are optional. This is the equivalent statement:
ALTER DATABASE db1
CHARACTER SET 'utf8mb4'
COLLATE 'utf8mb4_unicode_ci';
You can set a different database character set and/or collation for tables within the database using the CREATE TABLE
or ALTER TABLE
statement.
For additional information on character sets and collations, see "Character Sets in MariaDB Xpand" and "Collations in MariaDB Xpand".