What's the default password of mariadb on fedora?

Learn what's the default password of mariadb on fedora? with practical examples, diagrams, and best practices. Covers mysql, passwords, fedora development techniques with visual explanations.

Unraveling MariaDB's Default Password on Fedora

Hero image for What's the default password of mariadb on fedora?

Discover the nuances of MariaDB's default password behavior on Fedora, from initial installation to securing your database. This guide covers common scenarios and best practices.

When setting up a MariaDB server on Fedora, a common question arises: "What's the default password?" Unlike some other database systems or operating systems, MariaDB on Fedora typically does not come with a pre-set root password immediately after installation. This design choice prioritizes security by forcing users to configure a strong password from the outset, or by allowing passwordless access for local root users via Unix socket authentication.

Understanding Initial MariaDB Access on Fedora

Upon initial installation of MariaDB on Fedora, the root user for the database is usually configured to authenticate via the unix_socket plugin. This means that if you are logged in as the system's root user (or a user with sudo privileges), you can access the MariaDB root account without a password. This method enhances security by tying database access to operating system authentication, preventing remote password-based attacks on the root account by default.

flowchart TD
    A[Install MariaDB on Fedora] --> B{MariaDB Server Starts}
    B --> C{Root User Authentication Method?}
    C -->|Default: unix_socket| D[System Root User Accesses DB Root Without Password]
    C -->|Configured: password| E[DB Root User Requires Password]
    D --> F[Run 'mysql_secure_installation']
    E --> F

Initial MariaDB Access Flow on Fedora

sudo mysql -u root

Accessing MariaDB as root using Unix socket authentication

Securing Your MariaDB Installation

After gaining initial access, the most critical step is to secure your MariaDB installation. Fedora, like many other Linux distributions, provides a utility specifically for this purpose: mysql_secure_installation. This script guides you through several important security configurations, including setting a strong password for the database root user, removing anonymous users, disallowing remote root login, and removing the test database.

sudo mysql_secure_installation

Running the MariaDB security script

Changing or Resetting the Root Password

If you've already set a password and forgotten it, or if you wish to change it, you can do so by logging in as the system root user (or with sudo) and accessing MariaDB. The process involves updating the mysql.user table. It's important to flush privileges after making changes to ensure they take effect.

1. Access MariaDB as System Root

Log in to your Fedora system as root or use sudo to access the MariaDB client without a password:

sudo mysql -u root

2. Update Root Password

Once inside the MariaDB prompt, execute the following SQL command to set a new password. Replace 'YourNewStrongPassword' with your desired password:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourNewStrongPassword';

If you are using an older version of MariaDB or MySQL, you might need to use:

UPDATE mysql.user SET authentication_string = PASSWORD('YourNewStrongPassword') WHERE User = 'root' AND Host = 'localhost';

3. Flush Privileges

After updating the password, it's essential to reload the grant tables for the changes to take effect:

FLUSH PRIVILEGES;

4. Exit and Test

Exit the MariaDB client and then try logging in with the new password:

exit;
mysql -u root -p

You will be prompted to enter your new password.