Ask ChatGPT – Getting Started with MariaDB: A Comprehensive Guide for Beginners
This is the next in a series of posts on our explorations with ChatGPT that started with ChatGPT, OpenAI and MariaDB Foundation. Here, we asked ChatGPT to generate a blog post, and Chief Innovation Officer Daniel Black reviewed the results.
“Getting Started with MariaDB: A Comprehensive Guide for Beginners” is the question we asked ChatGPT. What we got is below. Rather than a blog on what you could have done yourself, I’ll look through the answer below and see how accurate it is, what could be better/worse, and assume this is some reflection on the references that the engine was trained on. So here it is:
Welcome to this comprehensive guide on getting started with MariaDB! MariaDB is a highly popular, open-source relational database management system that has won the hearts of many in the world of databases. MariaDB offers high performance, strong security, and excellent scalability, among other features, making it an excellent choice for a wide range of applications.
Whether you are a beginner or already have some experience with databases, this guide will walk you through the process of setting up, configuring, and using MariaDB in easy-to-follow steps. Let’s dive in!
So far so good. It’s hard to argue with flattery.
What is MariaDB?
MariaDB is an open-source relational database management system developed and maintained by the MariaDB Foundation. Initially developed as a fork of the MySQL database project, MariaDB aims to maintain compatibility with MySQL while providing additional features, stability, and performance improvements.
MariaDB plc (Corporation) does significantly more development and maintenance than us at the Foundation, so it would have been good to have that attributed. We also have other code contributions coming in and growing rapidly.
“compatibility with MySQL” is gaining several meanings, the most accurate implying compatibility with past MySQL releases, and not deprecating/removing features. Compatibly with MySQL going forward will always be a challenge. In general, if you want a new/compatible MySQL feature, request or vote for it on JIRA.
We want a good database for our users, regardless of what MySQL does.
Some of MariaDB’s notable features include:
- A powerful storage engine (InnoDB, Aria, MyISAM, etc.);
- Support for advanced querying through SQL;
- High-speed full-text search;
- High availability with multi-master replication;
- Easy scale-out using memcached APIs and other blocking clients.
“memcached APIs” is simply false. We’ve never supported it. The rest is pretty accurate. There are more powerful/interesting storage engines than MyISAM like Spider, Connect and S3 that I’d list if I was writing this.
Step 1: Installing MariaDB
The first step to getting started with MariaDB is to download and install the software. Installation instructions vary depending on your operating system.
Installing MariaDB on Linux
For Linux users, installing MariaDB is a simple process through the package manager. On Debian and Ubuntu systems, use the following commands:
sudo apt-get update sudo apt-get install mariadb-server
On Red Hat, CentOS, and Fedora systems, you’ll need to use the following:
sudo yum update sudo yum install mariadb-server
Installing MariaDB on Windows
For Windows users, the installation process is simple with the MariaDB .msi installer. Download the installer from the MariaDB downloads page, run it, and follow the on-screen instructions.
These are nice and simple. We do offer packages for newer MariaDB versions than the distro versions, but for simple instructions it’s pretty good. To meet the “comprehensive” requirement maybe Docker Official Images of MariaDB should be mentioned.
Step 2: Configuring MariaDB
After successfully installing MariaDB, you’ll need to configure a few settings.
It’s essential to secure your MariaDB installation to prevent unauthorized access. Thankfully, MariaDB includes a script called ‘mysql_secure_installation’ to help with this task. Run the following command in your terminal:
The script will guide you through the process of setting a root password, removing anonymous users, disabling remote root logins, and deleting the test database.
From MariaDB-10.4 this isn’t required any more. The distribution install will include a secure version with unix socket authentication so only the
rootunix user can login to the
rootMariaDB account. Distribution installs also don’t configure a test database. It’s not surprising that ChatGPT included this, it seems to be copied every time someone does a How To blog.
Adjusting MariaDB Settings
You may want to adjust various settings to improve MariaDB’s performance. To do this, open the MariaDB configuration file (my.cnf) with your preferred text editor.
On Linux, you can find this file in the /etc/mysql/ directory:
sudo nano /etc/mysql/my.cnf
Notably this applies to Debian-based only, for RPMs it’s found in
On Windows, the configuration file is located in the MariaDB installation directory, under ‘data’ folder:
notepad C:\Program Files\MariaDB #.#\data\my.ini
Make any changes you desire, save the file, and restart the MariaDB service for the changes to take effect.
For beginners, there’s nothing that should be changed apart from innodb_buffer_pool_size if you’ve got a decent active database size, and innodb_log_file_size if you are doing bulk insertions. Apart from that, changing defaults because of the look of a variable name, and feeling bigger is better, can cause more harm then good. Adjust only when needed.
Step 3: Using MariaDB
With MariaDB installed and configured, it’s time to give it a spin!
Connecting to MariaDB
To connect to the MariaDB server, use the ‘mysql’ command followed by the ‘-u’ flag (to specify a user) and the ‘-p’ flag (to be prompted for a password). For example:
mysql -u root -p
After entering your password, you’ll be greeted by the MariaDB command prompt, indicating a successful connection.
From MariaDB-10.4 onwards,
mariadbis the client name. We’d generally rather users appreciated that they were using MariaDB, to make it clearer what compatibility to expect, and to understand where and how to ask for help. Also access to the
rootuser from a non-unix root account isn’t guaranteed. So some pre-instructions like
sudo mariadb -u root -e 'create user dan@localhost identified with unix_socket; grant all on *.* to dan@localhost with grant option'(replaced with your unix user name) would be my preference before everyone starts using a
rootuser by default. Save
rootas a backup recovery user.
Basic MariaDB Commands
Here are some basic MariaDB commands you can use:
SHOW DATABASES;– Lists all databases on the server.
CREATE DATABASE dbname;– Creates a new database named ‘dbname.’
USE dbname;– Selects the ‘dbname’ database for subsequent queries.
SHOW TABLES;– Lists the tables within the currently selected database.
SELECT * FROM tablename;– Displays all rows in the ‘tablename’ table.
Remember to end each command with a semicolon (;).
In this guide, you’ve learned the basics of installing, configuring, and using MariaDB. While there’s much more to explore, you now have a solid foundation to build upon as you delve deeper into the world of MariaDB.
Don’t forget to visit the MariaDB Knowledge Base and the MariaDB Foundation Blog for more resources and articles to support your MariaDB journey. Good luck!
Nice and simple. The Getting Help with MariaDB Knowledge Base page lists a few more.
Overall I’m pretty happy with the way ChatGPT exposes the basics. I wouldn’t mind if eventually some things changed, but maybe I just need to write more blogs like this one.