mysql πώς να διορθώσετε την άρνηση πρόσβασης για τον χρήστη 'root'@'localhost&#39,

Πριν καταστρέψω κάτι, όταν συνδέομαι χρησιμοποιώντας $ mysql -u root -p, και εμφανίζω τις βάσεις δεδομένων:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| game_data          |
| test               |
+--------------------+

Στη συνέχεια προσπάθησα να δημιουργήσω έναν νέο χρήστη και παρατηρώ ότι κάτι δεν πάει καλά με τα PRIVILEGES.

Έτσι διέγραψα τους νέους χρήστες και υποθέτω ότι αφαίρεσα κατά λάθος τα 'root' και 'Admin'.

Στη συνέχεια προσπαθώ να δημιουργήσω ξανά τον 'root', αλλά λαμβάνω το σφάλμα Access denied όταν κάνω grant all privileges.

mysql> CREATE USER 'root'@'localhost' IDENTIFIED BY 'password';
mysql> grant all privileges on *.* to 'root'@'localhost' identified by 'password' with grant option;
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Αν συνδεθώ ξανά στη MySQL χρησιμοποιώντας $ mysql -u root -p, και εμφανίσω τις βάσεις δεδομένων,

+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+

Όλες οι άλλες βάσεις δεδομένων έχουν εξαφανιστεί.

Πώς μπορώ να διορθώσω τη MySQL τώρα;

Δεν μπορώ να βρω τη βάση δεδομένων 'mysql', δεν μπορώ να δημιουργήσω βάση δεδομένων, να δημιουργήσω χρήστη, οτιδήποτε προσπαθήσω να κάνω θα λάβω ένα σφάλμα.

Σφάλμα 1045 (28000): Απαγορεύεται η πρόσβαση για τον χρήστη 'root'@'localhost' (με χρήση κωδικού πρόσβασης: YES).

Θα πρέπει να επανεγκαταστήσω τη MySQL χρησιμοποιώντας το MacPorts; Αν επανεγκαταστήσω, θα χάσω τη βάση δεδομένων game_data, σωστά;

Λύση

Ακολουθήστε τα παρακάτω βήματα.

  1. Εκκινήστε την παρουσία ή τον δαίμονα του διακομιστή MySQL με την επιλογή --skip-grant-tables (ρύθμιση ασφαλείας).

     $ mysqld --skip-grant-tables
  2. Εκτελέστε αυτές τις εντολές.

     $ mysql -u root mysql
     $mysql> UPDATE user SET Password=PASSWORD('my_password') where USER='root',
     $mysql> FLUSH PRIVILEGES,

Εάν αντιμετωπίζετε το παραπάνω σφάλμα άγνωστου πεδίου Password χρησιμοποιήστε:

update user set authentication_string=password('my_password') where user='root';
  1. Τέλος, επανεκκινήστε το instance/daemon χωρίς την επιλογή --skip-grant-tables.

     $ /etc/init.d/mysql restart

Τώρα θα πρέπει να μπορείτε να συνδεθείτε με τον νέο σας κωδικό πρόσβασης.

$ mysql -u root -p

Εισάγετε τον κωδικό πρόσβασης: my_password

Επιδιόρθωση σφάλματος MySQL "Unable to lock ibdata1" (Αδυναμία κλειδώματος ibdata1)

sudo mv /usr/local/mysql/data/ibdata1 /usr/local/mysql/data/ibdata1.bak
sudo mv /usr/local/mysql/data/ib_logfile0 /usr/local/mysql/data/ib_logfile0.bak
sudo mv /usr/local/mysql/data/ib_logfile1 /usr/local/mysql/data/ib_logfile1.bak
sudo cp -a /usr/local/mysql/data/ibdata1.bak /usr/local/mysql/data/ibdata1
sudo cp -a /usr/local/mysql/data/ib_logfile0.bak /usr/local/mysql/data/ib_logfile0
sudo cp -a /usr/local/mysql/data/ib_logfile1.bak /usr/local/mysql/data/ib_logfile1
sudo /etc/init.d/mysql restart
Σχόλια (8)
grep 'temporary password' /var/log/mysqld.log
Sort date (newest date)

Μπορεί να δείτε κάτι σαν αυτό,

[root@SERVER ~]# grep 'temporary password' /var/log/mysqld.log
2016-01-16T18:07:29.688164Z 1 [Note] A temporary password is generated for root@localhost: O,k5.marHfFu
2016-01-22T13:14:17.974391Z 1 [Note] A temporary password is generated for root@localhost: b5nvIu!jh6ql
2016-01-22T15:35:48.496812Z 1 [Note] A temporary password is generated for root@localhost: (B*=T!uWJ7ws
2016-01-22T15:52:21.088610Z 1 [Note] A temporary password is generated for root@localhost: %tJXK7sytMJV
2016-01-22T16:24:41.384205Z 1 [Note] A temporary password is generated for root@localhost: lslQDvgwr3/S
2016-01-22T22:11:24.772275Z 1 [Note] A temporary password is generated for root@localhost: S4u+J,Rce_0t
[root@SERVER ~]# mysql_secure_installation

Ασφάλιση της εγκατάστασης του διακομιστή MySQL.

Enter password for user root: 

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

New password: 

Re-enter new password:

Αν δείτε ότι λέει

... Failed! Error: Your password does not satisfy the current policy requirements
That means your password needs to have a character such as ! . # - etc...
mix characters well, upper case, lower case, ! . , # etc...

New password: 

Re-enter new password: 
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
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: 

Re-enter new password: 

Estimated strength of the password: 100 
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,
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) : 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
 - 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! 
[root@SERVER ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.10 MySQL Community Server (GPL)

Παρακολουθήστε τα τελευταία 10 λεπτά [αυτού του βίντεο][1], σας διδάσκει πώς να το κάνετε.

Σχόλια (3)

Δοκιμάστε το:

mysql --no-defaults --force --user=root --host=localhost --database=mysql 
UPDATE user SET Password=PASSWORD('NEWPASSWORD') where USER='root';
FLUSH PRIVILEGES;
Σχόλια (5)