Databases - MariaDB / MySQL

MariaDB is a Database system that you can use to connect your Discord bot to a databasing system!

Did you join the SneakyHub discord server yet? If not, click here to join! Be sure that you also have a Discord bot already created. If not, refer to How to Create Server

==========================

SneakyHub has a built in MySQL and MariaDB support!

Create the Database

Go to the selected SneakyHub Panel Server, and click on the Databases tab. Here, we want to press New Database ( Figure 1A )

Name you database anything ( Figure 1B ), but DO NOT PUT ANYTHING FOR CONNECTIONS FROM TAB. That will make it so your Discord Bot cannot access the database.

You've now created your database successfully.

Connecting to your Discord Bot ( Discord.js )

We're going to use the MySQL package to connect your Discord Bot to our database.

After, go into your bots code, and somewhere in your code enter this:

const mysql = require('mysql');

const db = mysql.createConnection({
  host: '10.10.12.243',
  user: 'your_username', // your database username, required
  password: 'your_password', // the database password that was generated, required
  database: 'your_database', // what you named your database, required
});

db.connect((err) => {
  if (err) {
    console.error('Error connecting to MySQL:', err);
  } else {
    console.log('Connected to MySQL database');
  }
});

Fill out the rest of the rest of the required fields. After, you can start your bot and it should successfully say, Connected to MySQL database.

Last updated

The hosting company she told you not to worry about - SneakyHub 2021-2024