Installing MySQL on Fedora Linux using MariaDB. Since MySQL was sold to Oracle. MariaDB is a fork and open source version of MySQL.

Install MySQL on Fedora using MariaDB

$ sudo dnf install mariadb mariadb-server

Start MariaDB

$ sudo systemctl start mariadb

Config MariaDB

$ sudo mysql_secure_installation

In order to log into MariaDB to secure it, we’ll need the current password for the root user. If you’ve just installed MariaDB, and haven’t set the root password yet, you should just press enter here.

Enter current password for root (enter for none):

Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer ‘n’.

Switch to unix_socket authentication [Y/n] n
... skipping.

You already have your root account protected, so you can safely answer ‘n’.

Change the root password? [Y/n] n
... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.

Remove anonymous users? [Y/n] y
... Success!

Normally, root should only be allowed to connect from ‘localhost’. This ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
... Success!

By default, MariaDB comes with a database named ‘test’ that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.

Remove test database and access to it? [Y/n] y
Dropping test database...
... Success!
Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far will take effect immediately.

Reload privilege tables now? [Y/n] y
... Success!

Cleaning up…

All done! If you’ve completed all of the above steps, your MariaDB installation should now be secure.

Thanks for using MariaDB!

Import a database schema

Login with your database user root using sudo:

$ sudo mysql -uroot -p

Create a new database:

mysql> create database db1;

Create a user with the syntax create user [username] identified by [password]:

mysql> create user 'homer'@'localhost' identified by 'simpson';

Grant access:

mysql> grant all on db1.* to 'homer'@'localhost';


mysql> exit

Import the schema

$ mysql -u homer -p db1 < schema.sql

Import the data if this is in SQL script:

$ mysql -u homer -p db1 < data.sql

Connect to the database:

$ mysql -u homer -p db1

Import a database schema if grant access is set on the schema script

I worked on a project where grant access was set on the schema.sql script.

CREATE USER IF NOT EXISTS [email protected] IDENTIFIED BY `simpson`;
SET default_storage_engine=InnoDB;
SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;

    DEFAULT COLLATE utf8mb4_unicode_ci;
USE db1;

GRANT ALL PRIVILEGES ON `homer`.* TO 'homer'@'localhost';
GRANT ALL PRIVILEGES ON `db1`.* TO 'homer'@'localhost';

This means that this didn’t work, because the user was not previously created or granted access:

$ mysql -u homer -p db1 < schema.sql

I got this error:

ERROR 1227 (42000) at line 2: Access denied; you need (at least one of) the
CREATE USER privilege(s) for this operation

Login with your database user root using sudo:

$ sudo mysql -uroot -p

Create a new database:

mysql> create database db1;

Import like this:

$ sudo mysql -uroot -p db1 < schema.sql

Since the schema.sql creates the user and grants them access. Then you can run other scripts like this:

$ mysql -u homer -p db1 < data.sql
Enter password: 


Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 55
Server version: 10.4.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [db1]>

Using the help command

The help command helps you with syntax. Use like this:

MariaDB [db1]> help contents

This specific command shows a menu of these options:

For more information, type 'help <item>', where <item> is one of the
Account Management
Compound Statements
Data Definition
Data Manipulation
Data Types
Functions and Modifiers for Use with GROUP BY
Geographic Features
Help Metadata
Language Structure
Optimization and Indexes
Storage Engines
Table Maintenance
User-Defined Functions