added guide for mysql storage

JurgenKuyper 2022-05-05 10:09:46 +02:00
parent 0045bf9bef
commit 9d0e7db79b
1 changed files with 194 additions and 0 deletions

194
MySQL-MariaDB-Storage.md Normal file

@ -0,0 +1,194 @@
This option one of the 4 storage options of Dynmap. It is an advanced storage layout, for example a seperate service that hosts the database needs to be set-up, which will be explained in this guide.
## Linux
Install MySQL by typing the following command:
sudo apt install mysql-server
The MySQL database software is now installed, but its configuration is not yet complete.
To secure the installation, MySQL comes with a script that will ask whether you want to modify some insecure defaults. Initiate the script by typing the following:
sudo mysql_secure_installation
This script will ask if you want to configure the VALIDATE PASSWORD PLUGIN.
Warning: Enabling this feature is a judgment call. If enabled, passwords that dont match the specified criteria will be rejected by MySQL with
an error. This will cause issues if you use a weak password in conjunction with software that automatically configures MySQL user credentials,
such as the Ubuntu packages for phpMyAdmin. It is safe to leave validation disabled, but you should always use strong, unique passwords for
database credentials.``
Answer `Y` for yes, or anything else to continue without enabling.
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press `y|Y` for Yes, any other key for No:
If youve enabled validation, the script will also ask you to select a level of password validation. Keep in mind that if you enter 2 for the
strongest level you will receive errors when attempting to set any password which does not contain numbers, upper and lowercase letters,
and special characters, or which is based on common dictionary words.
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter `0 = LOW, 1 = MEDIUM and 2 = STRONG:` 1
Next, youll be asked to submit and confirm a root password:
Please set the password for root here.
New password:
Re-enter new password:
For the rest of the questions, you should press `Y` and hit the `ENTER` key at each prompt. This will remove some anonymous users and the test database, disable remote root logins, and load these new rules so that MySQL immediately respects the changes we have made.
Note that in Ubuntu systems running MySQL 5.7 (and later versions), the root MySQL user is set to authenticate using the auth_socket plugin by default rather than with a password. This allows for some greater security and usability in many cases, but it can also complicate things when you need to allow an external program (e.g., phpMyAdmin) to access the user.
## setup of the MySQL/MariaDB server.
Now, to setup the MySQL/MariaDB server.
It is recommended to create a new user/password with limited permissions for each application.
If you are setting up an external web server, you can also setup a firewall (iptables/firewalld/ufw/etc) to only allow the web server to connect to the database.
### Configurating the MySQL/MariaDB database
Using a terminal on the server that is hosting the minecraft server, we will create a new database and add some database users.
## Creating a new database in MySQL/MariaDB
mysql -u root -p
[Enter mysql root password if there is one]
mysql> CREATE DATABASE <dynmap_database_name>;
mysql> exit
<details>
<summary>Example (click to expand)</summary>
<pre><code>mysql -u root -p
[Enter mysql root password if there is one]
mysql> CREATE DATABASE DynmapDatabase;
mysql> exit</code></pre>
</details>
## Add new users
**note:**
If the MySQL server is on the same server as the minecraft server. <minecraftserver_ip> should just be localhost
<pre><code>mysql -u root -p
[Enter mysql root password if there is one]
mysql> CREATE USER '&lt;dynmap_user>'@'&lt;minecraftserver_ip>' IDENTIFIED BY '&lt;password>';
mysql> GRANT CREATE, DELETE, INSERT, SELECT, UPDATE ON &lt;dynmap_database>.* TO '&lt;dynmap_user>'@'&lt;minecraftserver_ip>';
mysql> FLUSH PRIVILEGES;
mysql> exit</pre></code>
<details>
<summary>Example if the mysql server and minecraft server are on the same server (click me to expand)</summary>
<pre><code>mysql -u root -p
[Enter mysql root password if there is one]
mysql> CREATE USER 'minecraftserver'@'localhost' IDENTIFIED BY 'password5678';
mysql> GRANT CREATE, DELETE, INSERT, SELECT, UPDATE ON 'minecraftserver'@'localhost'';
mysql> FLUSH PRIVILEGES;
mysql> exit</pre></code>
</details>
If you made a mistake and need to delete the mysql user. This is how you delete a user.
<pre><code>mysql> DROP USER '&lt;user_to_delete>'@'&lt;ip_you_used>';</code></pre>
After you create a new user, try logging into the user. (after you logout from the mysql root user via "exit")
<pre><code>mysql -u &lt;webserver_user> -p
[Enter user password]
mysql> exit</code></pre>
### MySQL Privileges/Permissions
MySQL has these permissions available to set to MySQL users.
* ALL PRIVILEGES - Grant all privileges to the user
* CREATE - Allows user to create databases/tables
* DELETE - Allows user to delete rows(data) from a table
* DROP - Allows user to drop databases and tables
* INSERT - Allows user to insert rows(data) to a table
* SELECT - Allows user to read from a database
* UPDATE - Allows user to update data in a table
## editing dynmap/configuration.txt
the last step is to configure the dynmap configuration.txt so it connects to the database and uses it for storage.
change the following part of the configuration.txt:
```yaml
storage:
# Filetree storage (standard tree of image files for maps)
type: filetree
# SQLite db for map storage (uses dbfile as storage location)
#type: sqlite
#dbfile: dynmap.db
# MySQL DB for map storage (at 'hostname':'port' with flags "flags" in database 'database' using user 'userid' password 'password' and table prefix 'prefix')
#type: mysql
#hostname: localhost
#port: 3306
#database: dynmap
#userid: dynmap
#password: dynmap
#prefix: ""
#flags: "?allowReconnect=true&autoReconnect=true"
```
to:
<details>
<summary>MySQL enabled (Click to expand)</summary>
```yaml
storage:
# Filetree storage (standard tree of image files for maps)
#type: filetree <- DONT FORGET TO COMMENT THIS OUT
# SQLite db for map storage (uses dbfile as storage location)
#type: sqlite
#dbfile: dynmap.db
# MySQL DB for map storage (at 'hostname':'port' with flags "flags" in database 'database' using user 'userid' password 'password' and table prefix 'prefix')
type: mysql
hostname: <mysql_ip>
port: <mysql_port>
database: <mysql_database>
userid: <dynmap_mysql_user>
password: <dynmap_mysql_password>
prefix: "" # Can add prefix for tables if you want
flags: "?allowReconnect=true&autoReconnect=true"
```
</details>
example:
<details>
<summary>MySQL example (Click to expand)</summary>
```yaml
storage:
# Filetree storage (standard tree of image files for maps)
#type: filetree <- DONT FORGET TO COMMENT THIS OUT
# SQLite db for map storage (uses dbfile as storage location)
#type: sqlite
#dbfile: dynmap.db
# MySQL DB for map storage (at 'hostname':'port' with flags "flags" in database 'database' using user 'userid' password 'password' and table prefix 'prefix')
type: mysql
hostname: localhost
port: 3306
database: dynmap
userid: dynmap
password: dynmap
prefix: "" # Can add prefix for tables if you want
flags: "?allowReconnect=true&autoReconnect=true"
```
</details>
## Windows
for windows we refer to the following guide: [guide](https://www.onlinetutorialspoint.com/mysql/install-mysql-on-windows-10-step-by-step.html)
after the server has been set up, follow the linux tutorial from this point on: https://github.com/webbukkit/dynmap/wiki/MySQL/MariaDB_Storage#setup-of-the-mysqlmariadb-server