|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Mysql und Ubuntu Xenial |
| 4 | +date: 2018-04-18 09:30:12 +0200 |
| 5 | +categories: debian xenial mariadb mysql server phpmyadmin |
| 6 | +--- |
| 7 | +Hier geht es heute darum wie man einen MySQL- beziehungsweise MariaDB Server aufsetzt und die Administration per PHPmyAdmin bereitstellt. |
| 8 | + |
| 9 | +# Was ist MariaDB |
| 10 | + |
| 11 | +MariaDB ist ein Fork von MySQL, der gestartet wurde als Oracle die Firma Sun - die MySQL Entwickelte übernommen hatte. Das ganze wär Anfänglich als 1zu1 Ersatz nutzbar, bietet aber inzwischen viele neue Funktionen. |
| 12 | + |
| 13 | +# Pakete installieren |
| 14 | + |
| 15 | +Als erstes musst du die benötigten Pakete installieren. |
| 16 | + |
| 17 | +{% highlight bash %} |
| 18 | +root@howto-root:~$ apt install apache2 phpmyadmin mariadb-server |
| 19 | +{% endhighlight %} |
| 20 | + |
| 21 | +Während der Installation wirst du nach dem Webserver gefragt. Hier wählst du `apache2` aus. Danach wirst du nach einem Datenbank-Passwort für PHPmyAdmin gefragt. Da dieses Passwort nur intern von PHPmyAdmin genutzt wird kannst du ein Zufälliges Passwort nutzen. |
| 22 | + |
| 23 | +**Achtung**: Bitte benutze nicht dieses Passwort. |
| 24 | + |
| 25 | +{% highlight bash %} |
| 26 | +root@howto-root:~$ dd if=/dev/urandom bs=100 count=1 2> /dev/null | tr -dc "A-Za-z0-9" && echo |
| 27 | +COEZNMEVKwLpP3y4wydzyasu |
| 28 | +{% endhighlight %} |
| 29 | + |
| 30 | +# MariaDB Server absichern |
| 31 | + |
| 32 | +Im nächsten Schritt sichen wir den Mysql-Server ab: |
| 33 | + |
| 34 | +{% highlight nginx %} |
| 35 | +root@howto-root:~# mysql_secure_installation |
| 36 | + |
| 37 | +NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB |
| 38 | + SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! |
| 39 | + |
| 40 | +In order to log into MariaDB to secure it, we'll need the current |
| 41 | +password for the root user. If you've just installed MariaDB, and |
| 42 | +you haven't set the root password yet, the password will be blank, |
| 43 | +so you should just press enter here. |
| 44 | + |
| 45 | +Enter current password for root (enter for none): |
| 46 | +OK, successfully used password, moving on... |
| 47 | + |
| 48 | +Setting the root password ensures that nobody can log into the MariaDB |
| 49 | +root user without the proper authorisation. |
| 50 | + |
| 51 | +You already have a root password set, so you can safely answer 'n'. |
| 52 | + |
| 53 | +Change the root password? [Y/n] y # hier musst du y Eingeben um ein Passwort zu vergeben. |
| 54 | +New password: # dann hier das neue Passwort |
| 55 | +Re-enter new password: # und das noch einmal wiederholen |
| 56 | +Password updated successfully! |
| 57 | +Reloading privilege tables.. |
| 58 | + ... Success! |
| 59 | + |
| 60 | + |
| 61 | +By default, a MariaDB installation has an anonymous user, allowing anyone |
| 62 | +to log into MariaDB without having to have a user account created for |
| 63 | +them. This is intended only for testing, and to make the installation |
| 64 | +go a bit smoother. You should remove them before moving into a |
| 65 | +production environment. |
| 66 | + |
| 67 | +Remove anonymous users? [Y/n] y # die brauchst du nicht, also weg damit. |
| 68 | + ... Success! |
| 69 | + |
| 70 | +Normally, root should only be allowed to connect from 'localhost'. This |
| 71 | +ensures that someone cannot guess at the root password from the network. |
| 72 | + |
| 73 | +Disallow root login remotely? [Y/n] y # erlaubt Root-Zugriff nur vom Server selbst |
| 74 | + ... Success! |
| 75 | + |
| 76 | +By default, MariaDB comes with a database named 'test' that anyone can |
| 77 | +access. This is also intended only for testing, and should be removed |
| 78 | +before moving into a production environment. |
| 79 | + |
| 80 | +Remove test database and access to it? [Y/n] y # Test Datenbanken entfernen |
| 81 | + - Dropping test database... |
| 82 | + ... Success! |
| 83 | + - Removing privileges on test database... |
| 84 | + ... Success! |
| 85 | + |
| 86 | +Reloading the privilege tables will ensure that all changes made so far |
| 87 | +will take effect immediately. |
| 88 | + |
| 89 | +Reload privilege tables now? [Y/n] y # Rechte neu laden. |
| 90 | + ... Success! |
| 91 | + |
| 92 | +Cleaning up... |
| 93 | + |
| 94 | +All done! If you've completed all of the above steps, your MariaDB |
| 95 | +installation should now be secure. |
| 96 | + |
| 97 | +Thanks for using MariaDB! |
| 98 | + |
| 99 | +{% endhighlight %} |
| 100 | + |
| 101 | +# Root Zugriff über TCP Verbindungen erlauben |
| 102 | + |
| 103 | +Nach der Installation erlaubt der MariaDB Server den Root-Zugriff nur über den lokalen Socket `58nH61OyNICEyHvzo7sD2K6aDdrUyv16r`, aber nicht über den Port `localhost:3306`. PHPmyAdmin und viele Anwendungen (z.B. Minecraft) gereifen aber im Normalfall über den Port auf deinen Server zu. |
| 104 | + |
| 105 | +Hiermit aktivieren wir den Zugriff über den Port: |
| 106 | + |
| 107 | +{% highlight bash %} |
| 108 | +root@howto-root.de:~# mysql mysql <<EOF |
| 109 | +update user set plugin = '' where Host = 'localhost' and User = 'root'; |
| 110 | +flush privileges; |
| 111 | +EOF |
| 112 | +{% endhighlight %} |
| 113 | + |
| 114 | +# Root-Passwort speichern |
| 115 | + |
| 116 | +Um schneller auf der Konsole auf den Server zuzugreifen kannst du das Passwort speichern. |
| 117 | + |
| 118 | +Datei: `~/.my.cnf` |
| 119 | + |
| 120 | +{% highlight bash %} |
| 121 | +[client] |
| 122 | +host = localhost |
| 123 | +user = root |
| 124 | +password = HIER_STEHT_DEIN_PASSWORD |
| 125 | +socket = /var/run/mysqld/mysqld.sock |
| 126 | +{% endhighlight %} |
| 127 | + |
| 128 | +**Wichtig** Damit niemand das Passwort aus der Datei lesen kann, setzen wir die passenden Rechte: |
| 129 | + |
| 130 | +{% highlight bash %} |
| 131 | +root@howto-root.de:~# chmod 600 .my.cnf |
| 132 | +{% endhighlight %} |
| 133 | + |
| 134 | +# Auf PHPmyAdmin zugreifen |
| 135 | + |
| 136 | +Du kannst dich jetzt bei PHPmyAdmin mit deinem Server-Passwort anmelden. |
| 137 | + |
| 138 | +Die URL lautet: `http://deine_ip_addresse/phpmyadmin` |
| 139 | + |
| 140 | +Viel Spaß :) |
0 commit comments