91 lines
4.6 KiB
Markdown
91 lines
4.6 KiB
Markdown
<!--{"title": "MySQL auf Linux installieren", "date": "2024-04-08", "slug": "mysql-auf-linux-installieren", "cover": "/static/img/mysql-auf-linux-installieren.webp"}-->
|
|
> Kennzeichnung gemäß Artikel 52 Absatz 1 EU AI Act: [💜 <ins>Kein Einsatz von KI</ins>](/page/ai)
|
|
|
|
**Sie möchten einen schnellen und performanten MySQL-Server betreiben und haben bislang MySQL nur Windows genutzt? Versuchen Sie es doch mal mit Linux.
|
|
Linux ist kein Hexenwerk und die Performance wird Sie überraschen. Wir zeigen Ihnen hier alle relevanten Schritte für eine erfolgreiche Umsetzung und einen stabilen Betrieb.**
|
|
|
|
Hier zeige ich euch, wie ihr einen MySQL-Server auf Linux (Ubuntu 22.04) installiert.
|
|
|
|
Sie benötigen eine physische oder virtuelle Maschine mit Linux. Wir verwenden in diesem Beitrag die aktuelle Core-Server Version von Ubuntu mit Long-Term-Support (LTS).
|
|
|
|
Beachten Sie, das Server-Maschinen grundsätzlich mit einer statischen IP-Adresse eingerichtet sein sollten. Alternativ können Sie auch eine DHCP-Reservierung verwenden. Wir empfehlen jedoch die Nutzung einer statischen IP-Konfiguration.
|
|
|
|
Melden Sie sich an Ihrer Linux-Konsole an und führen folgendes Kommando aus, um den Software-Dienst zu aktualisieren: ```sudo apt update```.
|
|
|
|
Installieren Sie das MySQL-Server-Paket mit folgendem Kommando: ```sudo apt install mysql-server```.
|
|
|
|
Starten Sie den neu installierten MySQL-Dienst mit diesem Kommando: ```sudo systemctl start mysql.service```.
|
|
|
|
Rufen Sie die MySQL-Konsole auf: ```sudo mysql```.
|
|
|
|
Geben Sie nacheinander die folgenden vier Kommandos ein. In Zeile 1 ersetzen Sie "passwort" durch Ihr neues Root- (Administrator-) Passwort. In Zeile 2 ersetzen Sie "starkespasswort" durch Ihr neues Administrator-Passwort. Verwenden Sie hier ein maximal starkes Passwort, da diesem Benutzer erlaubt wird, sie von externen Hosts (%) anzumelden. Ersetzen Sie zudem in Zeile 2 "deinuser" durch den von Ihnen gewünschten Benutzernamen.
|
|
|
|
```
|
|
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'passwort';
|
|
CREATE USER 'deinuser'@'%' IDENTIFIED WITH mysql_native_password BY 'starkespasswort';
|
|
GRANT ALL PRIVILEGES on *.* TO 'deinuser'@'%' WITH GRANT OPTION;
|
|
FLUSH PRIVILEGES;
|
|
```
|
|
|
|
Verlassen Sie die MySQL-Konsole mit diesem Befehl: ```exit```.
|
|
|
|
Führen Sie jetzt die erweiterte Konfiguration durch:
|
|
|
|
Setzen Sie folgendes Kommando ab: ```sudo mysql_secure_installation```.
|
|
|
|
```
|
|
Securing the MySQL server deployment.
|
|
Enter password for user root:
|
|
VALIDATE PASSWORD COMPONENT 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 component?
|
|
Press y|Y for Yes, any other key for No:
|
|
Using existing password for root.
|
|
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n
|
|
... skipping.
|
|
By default, a MySQL installation has an anonymous user,
|
|
allowing anyone to log into MySQL without having to have
|
|
a user account created for them. This is intended only for
|
|
testing, and to make the installation go a bit smoother.
|
|
You should remove them before moving into a production
|
|
environment.
|
|
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
|
|
Success.
|
|
|
|
Normally, root should only be allowed to connect from
|
|
'localhost'. This ensures that someone cannot guess at
|
|
the root password from the network.
|
|
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
|
|
... skipping.
|
|
By default, MySQL comes with a database named 'test' that
|
|
anyone can access. This is also intended only for testing,
|
|
and should be removed before moving into a production
|
|
environment.
|
|
|
|
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
|
|
- Dropping test database...
|
|
Success.
|
|
- Removing privileges on test database...
|
|
Success.
|
|
Reloading the privilege tables will ensure that all changes
|
|
made so far will take effect immediately.
|
|
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
|
|
Success.
|
|
All done!
|
|
```
|
|
|
|
Bearbeiten Sie die Konfiguration mit folgendem Befehl: ```sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf```. Ändern Sie die Konfiguration auf die unten genannten Werte.
|
|
|
|
```
|
|
bind-address = 0.0.0.0
|
|
mysqlx-bind-address = 0.0.0.0
|
|
```
|
|
|
|
Starten Sie den Dienst mit folgendem Kommando neu: ```sudo systemctl restart mysql.service```.
|
|
|
|
Nun ist Ihr MySQL-Server auf Linux startbereit.
|
|
|
|
Möglicherweise interessiert Sie auch unser Artikel zu PHPMyAdmin in Docker?
|
|
|
|
[PHPMyAdmin mit Serverauswahl im Homelab mittels Docker bereitstellen](/post/phpmyadmin-mit-serverauswahl-im-homelab-mittels-docker-bereitstellen) |