ERROR 1045 (28000): Access denied for user ‚root’@’localhost‘ (using password: YES)

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)  

Den Server stoppen:

sysvorOrt# systemctl stop mysqld.service

Erstelle ein MySQL-Dienstverzeichnis.

sysvorOrt# mkdir /var/run/mysqld

Gib MySQL die Erlaubnis, mit dem erstellten Verzeichnis zu arbeiten.

sysvorOrt# chown mysql: /var/run/mysqld

Starte MySQL ohne Berechtigung und Netzwerküberprüfung.

sysvorOrt /home/michi # mysqld_safe –skip-grant-tables –skip-networking &
[1] 4784

Melde dich ohne Passwort beim Server an.

 mysql -u root mysql

Looks like your data directory ‚/var/lib/mysql‘ is already initialized!

sysvorOrt /home/michi # emerge --config =dev-db/mysql-8.0.27


Configuring pkg...

 * Looks like your data directory '/var/lib/mysql' is already initialized!
 * Please rename or delete its content if you wish to initialize a new data directory.
 * ERROR: dev-db/mysql-8.0.27::gentoo failed (config phase):
 *   mysql data directory at '/var/lib/mysql' looks already initialized!
 * 
 * Call stack:
 *     ebuild.sh, line 122:  Called pkg_config
 *   environment, line 3048:  Called die
 * The specific snippet of code:
 *               die "${PN} data directory at '${MY_DATADIR}' looks already initialized!";
 * 
 * If you need support, post the output of `emerge --info '=dev-db/mysql-8.0.27::gentoo'`,
 * the complete build log and the output of `emerge -pqv '=dev-db/mysql-8.0.27::gentoo'`.
 * The complete build log is located at '/var/tmp/portage/dev-db/mysql-8.0.27/temp/build.log.
 * The ebuild environment file is located at '/var/tmp/portage/dev-db/mysql-8.0.27/temp/envionment'.
 * Working directory: '/var/tmp/portage/dev-db/mysql-8.0.27/empty'
 * S: '/var/tmp/portage/dev-db/mysql-8.0.27/work/mysql-8.0.27'

In diesem Fall ist die MySQL Installation und Konfiguration schon einmal durchgeführt worden.
Infos zum Thema gibt es hier: https://wiki.gentoo.org/wiki/MySQL/Startup_Guide/de

Your machine must NOT be named localhost

Bei der gewünschten Konfiguration von MySQL wird der Fehler „Your machine must NOT be named localhost“ angezeigt.

Wenn der obige Befehl abbricht, weil der Hostname auf localhost lautet, kann man diesen auf einen anderen Wert z.B. gentoo ändern. Dazu ist /etc/conf.d/hostname zu ändern und /etc/init.d/hostname neu zu starten.