Original text: developer.fedoraproject.org/tech/databa…

Original authors: Adam Samalik, FaramosCZ, Honza Horak, antoninmrkvica, Ricky grassmuck

MariaDB is a separate community maintained version of MySQL that forks and is a perfect substitute for MySQL. Detailed information about MariaDB can be found on the upstream feature introduction page, and the main differences between MariaDB and MySQL can be found in the compatibility documentation

Fedora provides a version of MySQL

MariaDB is the official Fedora recommended version of MySQL. MariaDB is a perfect substitute for MySQL in the vast majority of applications — in general, the vast majority of MySQL documentation works for MariaDB as well.

If you do need to install community MySQL on Fedora, you can use the community MySQL package (community-mysql).

Fedora usually only provides the latest stable version of MariaDB, and if you need additional versions (which Fedora does not support), you can download them from the COPR repository provided by the maintainer. For information on the current version of MariaDB, consult the upstream documentation. In Fedora, MariaDB packages are named MariaDB (client tool) and MariadB-server (service daemon)

If you want an older version, you can install the MariaDB 5.5 package collection or packages provided upstream.

Fedora provides MariaDB with the Galera patch in a package called Mariadb-Galera-Server. The Galera package provides wsREP plug-ins. See “How to Install MariaDB Galera in Fedora” at the end of this article for more information.

Install MariaDB on Fedora

  1. Install MariaDB client:

    $ sudo dnf install mariadb
    Copy the code
  2. Install the MariaDB server:

    $ sudo dnf install mariadb-server
    Copy the code
  3. If you need to connect to MariaDB using a GUI, you can install phpMyAdmin:

    $ sudo dnf install phpMyAdmin
    Copy the code
  4. Or install Libre Office Base with MariaDB JDBC plug-in:

    $ sudo dnf install libreoffice-base mariadb-java-client
    Copy the code
  5. If you want to connect to MariaDB using ODBC, you need to install the unixODBC and Mariadb-connector-ODBC packages:

    $ sudo dnf install mariadb-connector-odbc
    Copy the code

The basics of using MariaDB in Fedora

By default, the MariaDB running on port 3306, and will be in the local/var/lib/mysql/mysql. The sock to create a local Unix socket. By default, data is stored in the /var/lib/mysql directory and logs are stored in the /var/log/mariadb/ directory. If you want to change the default directory above, take care to reconfigure the SELinux context and owner.

When the installation is complete, the data directory is empty and will be initialized when MariaDB is first started.

Run the following command to start MariaDB:

$ sudo systemctl start mariadb
Copy the code

Set MariaDB to start automatically when the system starts:

$ sudo systemctl enable mariadb
Copy the code

The root user of MariaDB does not have a default password and can directly connect to the database

mysql -u root
Copy the code

It is recommended to run the Secure Setup Assistant to make MariaDB more secure:

$ sudo mysql_secure_installation
Copy the code

The tool asks you to answer questions interactively. Please set a separate complex password in this tool rather than using the current system administrator password directly — MySQL user root is authenticated independently.

Configuration MariaDB

The MariaDB client and server can be configured by editing all.cnf files under /etc/my.cnf, ~/.my.cnf, and /etc/my.cnf.d/. For detailed configuration methods, refer to the upstream documentation.

Configure the MariaDB server for local development

When developing applications using MariaDB as a storage engine, developers typically need a user account with full access to a particular database scheme. To create this specific account and database, run the following command:

$ sudo systemctl start mariadb $ sudo systemctl enable mariadb $ sudo mysql_secure_installation ... My Account sudo mysql -u root -p MariaDB [(none)]> create database db1; Query OK, 1 row affected (0.00 SEC) MariaDB [(none)]> CREATE USER 'valeria'@'localhost' IDENTIFIED BY 'secretpass'; Query OK, 1 row affected (0.00 SEC) MariaDB [(none)]> CREATE USER 'valeria'@'localhost' IDENTIFIED BY 'secretpass'; Query OK, 0 rows affected (0.00 SEC) MariaDB [(none)]> GRANT ALL ON db1.* TO 'valeria'@'localhost'; Query OK, 0 rows affected (0.00 SEC) MariaDB [(none)]> exit ByeCopy the code

You can then use this account to use the database from the MariaDB command line tool:

$ mysql -u valeria -p
Copy the code

(If the command contains -p without a password, the program will ask you to enter it separately.)

In different frameworks or libraries, you can access the database using the user name and password you just set.

How can I use MariaDB during the development of a production environment

To use MariaDB in production development, developers need to be careful about risk control when starting the service. This requires:

  • Use what was mentioned abovemysql_secure_installation
  • Do not accept connection requests from all addresses unless you really need them
  • Use complex passwords
  • Provide just enough permissions for your application

By default, MariaDB does not accept connection requests from other computers. If you want to connect to MariaDB from another computer, you need to do the following:

Open port 3306:

firewall-cmd --permanent --zone=public --add-port=3306/tcp
Copy the code

Modify the mysql configuration file mentioned above to add the following configuration items to allow receiving requests from all interfaces (or as required) :

The bind - address = 0.0.0.0Copy the code

Other Common Configurations

You can modify the configuration parameters of the MariaDB server by creating a configuration file in the /etc/my.conf.d/ directory.

The following example shows/etc/my. Conf. D/myconfig. CNF file content. This file contains some frequently modified configuration options (users can use any variable that fits their needs) :

# The maximum permitted number of simultaneous client connections: Max_connections = 20 # The minimum length of The word to be included in a FULLTEXT index: Ft_min_word_len = 3 # The maximum length of The word to be included in a FULLTEXT index: Ft_max_word_len = My Account # In case the native AIO is broken, it can be disabled by: Innodb_use_native_aio = 0 # Log slow queries # log slow query:  slow_query_log = 1 slow_query_log_file = "/var/log/mariadb/slowquery.log" # Log all queries (e.g. for debugging): # log query: (all) for the debug and scene general_log = 1 general_log_file = ". / var/log/mariadb/query log"Copy the code

After modifying the configuration file, run the $sudo systemctl restart mariadb command to restart the service.

Install MariaDB Galera on Fedora

The MariaDB Galera cluster is a MariaDB multi-master asynchronous cluster.

Install the MariaDB Galera Server package with the following command:

$ sudo dnf install mariadb-galera-server galera
Copy the code

MariaDB Galera uses multiple underlying MariaDB packages and provides the same service name as the original MariaDB. So MariaDB Galera can still be started with the following command:

$ sudo systemctl start mariadb
Copy the code

Get the MariaDB Docker container

$ sudo docker pull fedora/mariadb
Copy the code

Extend MariaDB with Fedora’s extensions

The MariaDB Connect storage engine enables MariaDB to access external local or remote data (MED). To install the engine, run the following command:

$ sudo dnf install mariadb-connect-engine
Copy the code

To install the Open Query GRAPH computing engine, run:

$ sudo dnf install mariadb-oqgraph-engine
Copy the code

Use the MariaDB server as a dynamically linked library

In Fedora, the MariaDB server can also be used as a dynamic library. The library (libmysqld.so) is provided by the mariadb-embedded package and the corresponding header package is provided by the corresponding devel package mariadb-embedded-devel.

However, this is not recommended. MySQL 8 no longer provides inline libraries, and we expect MariaDB to drop support for inline libraries at some point in the future.

\