[RUBY] Mysql2 :: Error :: ConnectionError: Zugriff für user'root '@' localhost 'verweigert (mit Passwort: YES)

Problem

Ich versuche, ein in einer lokalen Umgebung erstelltes Portfolio (persönliche App) für AWS bereitzustellen.

Beim Versuch, eine Datenbank in einer Produktionsumgebung zu erstellen, wurde der folgende Fehler angezeigt.

Error

[ec2-user@ip-00-0-0-000 pfc-master]$ rake db:create RAILS_ENV=production
Access denied for user 'root'@'localhost' (using password: YES)

Lösung

① Bestätigen Sie das temporäre Passwort

[ec2-user@ip-00-0-0-000 ~]$ sudo cat /var/log/mysqld.log | grep "temporary password"

Überprüfen Sie das temporäre Kennwort, das automatisch generiert wurde, als Sie MySQL im MySQL-Protokoll installiert haben.

② Ändern Sie die Regeln für die Kennworteinstellung

Wenn Sie Ihr MySQL-Passwort ändern, ohne dieses Verfahren zu befolgen, wird der folgende Fehler angezeigt.

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

Die Standardregel lautet ** "Die Kennwortlänge muss mindestens 8 Zeichen betragen, sowohl Klein- als auch Großbuchstaben enthalten und Sonderzeichen enthalten" **.

Wenn das bereits in database.yml festgelegte Kennwort diese Regel erfüllt, muss die Regel nicht geändert werden. Wenn es jedoch nicht der Regel wie" Kennwort "entspricht, ist es schwierig, die Regel zu ändern. Das würde die Prüfung deaktivieren.

$ sudo vi /etc/my.cnf

Öffnen Sie vim mit / etc / my.cnf

[mysqld]
validate-password=OFF

Hinzufügen.

Starten Sie MySQL neu, damit die Einstellungen wirksam werden.

$ sudo systemctl restart mysqld.service

Referenz: MySQL 5.7 * Es ist schwierig, das Kennwort mit der Richtlinie abzugleichen

③ Passwort ändern

[ec2-user@ip-00-0-0-000 ~]$ mysql_secure_installation

Das erste Setup nach der Installation von MySQL 5.7 ↑ Da die Methode zum Ändern des Kennworts in diesem Artikel beschrieben wurde, ändern Sie das Kennwort, das darauf verweist.

Geben Sie das in ① bestätigte temporäre Passwort unter "Initiales Passwort" ein. Geben Sie das in database.yml festgelegte Passwort unter "Neues Passwort" ein.

Beantworten Sie alle nachfolgenden Ja- oder Nein-Fragen mit y (Ja).

$ mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:Geben Sie das ursprüngliche Passwort ein

The existing password for the user account root has expired. Please set a new password.

New password:Geben Sie ein neues Kennwort ein

Re-enter new password:Geben Sie das gleiche neue Passwort erneut ein

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: y

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: 0
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password:Geben Sie ein neues Passwort gemäß der Richtlinie ein

Re-enter new password:Geben Sie das neue Passwort erneut ein

Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user, 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) : y
Success.

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 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!

Referenzartikel

Recommended Posts

Mysql2 :: Error :: ConnectionError: Zugriff für user'root '@' localhost 'verweigert (mit Passwort: YES)
Zugriff für user'root '@' localhost 'verweigert (mit Passwort: NO) Korrekturmaßnahme für Fehler
Zugriff für user'root '@' localhost 'verweigert (mit Passwort: YES) und aufgegeben
Beheben Sie Mysql2 :: Error :: ConnectionError