Create new database mysql encoding

To create a new database with a specific encoding in MySQL, you can use the following steps:

  1. Connect to your MySQL server using the command-line tool or a GUI tool like phpMyAdmin.
  2. Create a new database using the CREATE DATABASE statement. For example:
    CREATE DATABASE mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

    In this example, we're creating a database named mydatabase with the following characteristics:

  1. Verify that the database has been created with the correct encoding by running the following query:

    SHOW VARIABLES LIKE 'character_set_database';

    This should return the value utf8mb4 for the character_set_database variable, indicating that the database is using the specified encoding.

  2. Create a new table in the database using the CREATE TABLE statement. For example:

    CREATE TABLE mytable (
    id INT PRIMARY KEY,
    name VARCHAR(255) NOT NULL
    );
  3. Verify that the table has been created with the correct encoding by running the following query:

    SHOW TABLE STATUS LIKE 'mytable';

    This should return the value utf8mb4 for the Default character set column, indicating that the table is using the specified encoding.

Note: If you're using an older version of MySQL that doesn't support the utf8mb4 character set, you may need to use a different character set, such as utf8. However, utf8 has some limitations and is not recommended for new databases.

Also, you can use the CREATE DATABASE statement with the DEFAULT CHARACTER SET and DEFAULT COLLATE options to set the default encoding and collation for the database. For example:

CREATE DATABASE mydatabase DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;

This will create a new database with the specified encoding and collation, and all tables created in the database will inherit these settings.