|
1 | 1 | +++ |
2 | 2 | title = "MariaDB" |
3 | | -description = "Setting up a MariaDB server on Ubuntu 16.04 LTS" |
| 3 | +description = "Setting up a MariaDB server on Ubuntu LTS" |
4 | 4 | date = 2018-02-18T20:30:47-05:00 |
5 | 5 | weight = 23 |
6 | 6 | draft = false |
7 | | -bref = "This guide will walk you through on setting up a MariaDB server on Ubuntu 16.04 LTS" |
| 7 | +bref = "This guide will walk you through on setting up a MariaDB server on Ubuntu LTS" |
8 | 8 | toc = true |
9 | 9 | +++ |
10 | 10 |
|
11 | | -### Adding Repo |
| 11 | +SourceBans++ requires MariaDB >= 10.0 (or MySQL >= 5.6). The instructions below target current Ubuntu LTS releases (22.04 / 24.04) and install the MariaDB 10.11 LTS series. |
| 12 | + |
| 13 | +### Option A: Install from the Ubuntu repository |
| 14 | + |
| 15 | +Recent Ubuntu LTS releases ship a recent enough MariaDB by default and this is the simplest path: |
12 | 16 |
|
13 | 17 | ``` |
14 | | -sudo apt-get install software-properties-common |
15 | | -sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 |
16 | | -sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.2/ubuntu xenial main' |
17 | | -sudo apt-get update |
| 18 | +sudo apt update |
| 19 | +sudo apt install mariadb-server |
18 | 20 | ``` |
19 | 21 |
|
20 | | -### Installing |
| 22 | +### Option B: Install from MariaDB's official repository |
| 23 | + |
| 24 | +Use this if you want a newer release than your distro provides. The legacy `apt-key adv` approach is deprecated; use `signed-by` instead. |
21 | 25 |
|
22 | 26 | ``` |
23 | | -sudo apt-get install mariadb-server |
| 27 | +sudo apt install curl gnupg ca-certificates apt-transport-https |
| 28 | +sudo curl -o /etc/apt/keyrings/mariadb-keyring.pgp 'https://mariadb.org/mariadb_release_signing_key.pgp' |
| 29 | +echo "deb [signed-by=/etc/apt/keyrings/mariadb-keyring.pgp] https://deb.mariadb.org/10.11/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list |
| 30 | +sudo apt update |
| 31 | +sudo apt install mariadb-server |
24 | 32 | ``` |
25 | 33 |
|
| 34 | +The official [MariaDB Repository Configuration Tool](https://mariadb.org/download/?t=repo-config) can generate the same snippet for any distro/version. |
| 35 | + |
26 | 36 | ### Setup |
27 | 37 |
|
28 | | -Run `mysql_secure_installation` |
| 38 | +Run `sudo mysql_secure_installation` |
29 | 39 |
|
30 | 40 | ### Configuring |
31 | 41 |
|
| 42 | +Skip this section if your web panel and game servers connect to the database from the same host (`localhost`). |
| 43 | + |
32 | 44 | 1. Navigate to your MariaDB config (Ex: <samp>/etc/mysql/mariadb.conf.d/50-server.cnf</samp>) |
33 | 45 |
|
34 | | -2. Comment out `bind-address` by prefixing it with a `#`, so it looks like `#bind-address = 127.0.0.1` |
| 46 | +2. Either comment out `bind-address` by prefixing it with a `#`, or set it to `0.0.0.0` (IPv4) or `::` (IPv4 + IPv6) to listen on all interfaces |
35 | 47 |
|
36 | | -3. Restart MySQL via `sudo systemctl restart mysql` |
| 48 | +3. Restart MariaDB via `sudo systemctl restart mariadb` |
37 | 49 |
|
38 | 50 | ### Granting Permission |
39 | 51 |
|
40 | | -Sign in to MySQL shell via `sudo mysql -u root -p` and enter your password |
| 52 | +Sign in to MariaDB shell via `sudo mariadb -u root -p` (or `sudo mysql -u root -p`) and enter your password |
41 | 53 |
|
42 | 54 | Run the following, adjusting it to suit your own needs |
43 | 55 |
|
44 | 56 | * <mark>Username</mark> - The user you wish to create |
45 | 57 |
|
46 | | -* <mark>Host</mark> - The host you wish to whitelist |
| 58 | +* <mark>Host</mark> - The host you wish to whitelist (e.g. `localhost`, an IP, or `%` for any host) |
47 | 59 |
|
48 | 60 | * <mark>Password</mark> - The password to use for the user creation |
49 | 61 |
|
50 | 62 | ``` |
51 | | -GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'HOST' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION; |
| 63 | +CREATE USER 'USERNAME'@'HOST' IDENTIFIED BY 'PASSWORD'; |
| 64 | +GRANT ALL PRIVILEGES ON `DATABASENAME`.* TO 'USERNAME'@'HOST'; |
52 | 65 | FLUSH PRIVILEGES; |
53 | 66 | ``` |
54 | 67 |
|
| 68 | +The combined `GRANT ... IDENTIFIED BY ...` syntax is removed in MariaDB 10.4+ / MySQL 8+, so create the user first and grant privileges in a second statement. Granting on a specific database (rather than `*.*`) keeps the principle of least privilege. |
| 69 | + |
55 | 70 | ### Done! |
56 | 71 |
|
57 | 72 | From here on, you are done with setting up a MariaDB server! |
0 commit comments