2013-06-03 07:32:18 +0000 2013-06-03 07:32:18 +0000
130
130
Advertisement

mysql come risolvere Accesso negato per l'utente 'root'@'localhost'

Advertisement

Prima di rovinare qualcosa, quando faccio il login usando $ mysql -u root -p, e mostro i database:

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

Poi ho provato a creare un nuovo utente e ho notato che qualcosa non va con i PRIVILEGI.

Così ho cancellato i nuovi utenti, e credo di aver rimosso la ‘root’ e ‘Admin’ accidentalmente.

Poi ho provato a creare di nuovo la ‘root’, ma ho ottenuto l'errore di Access denied quando ho concesso tutti i privilegi.

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)
``` ```
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+

Se faccio di nuovo il login a MySQL usando $ mysql -u root -p, e mostro i database,

&001 &001

Tutti gli altri database sono andati.

Come faccio a correggere MySQL adesso?

Non riesco a trovare il database ‘mysql’, non riesco a creare un database, creare un utente, qualsiasi cosa provo a fare otterrò un errore.

ERROR 1045 (28000): Accesso negato per l'utente ‘root’@‘localhost’ (usando la password: SI).

Devo reinstallare MySQL usando MacPorts? Se reinstallare, perderò il database game_data, giusto?

Advertisement

Risposte (6)

138
138
138
2013-06-03 07:35:27 +0000

Seguire i seguenti passi.

    1. Avviare l'istanza o il demone del server MySQL con l'opzione --skip-grant-tables (impostazione di sicurezza).
  1. Avviare l'istanza o il demone del server MySQL con l'opzione --skip-grant-tables (impostazione di sicurezza). 3. Eseguire queste istruzioni.

Se si affronta il campo sconosciuto Errore di password di cui sopra utilizzare:

update user set authentication_string=password('my_password') where user='root';
  1. Premere il pulsante di sicurezza. 2. Infine, riavviare l'istanza/daemon senza l'opzione my_password.

Ora dovreste essere in grado di connettervi con la nuova password.

$ mysql -u root -p

Inserire la password: &007

Fix for MySQL “Impossibile bloccare ibdata1” errore

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
74
74
74
2016-09-28 15:01:12 +0000

Nessuna di queste cose mi è stata d'aiuto. Ho scoperto che dovevo cancellare il metodo del plugin. In 5.6, ho potuto fare:

sudo mysql -u root
use mysql;
[mysql] update user set plugin='' where User='root';
[mysql] flush privileges;
``` ```
sudo mysql -u root
use mysql;
[mysql] update user set plugin='mysql_native_password' where User='root';
[mysql] flush privileges;

In 5.7, ho trovato che avevo bisogno di:

&001 &001

Secondo i documenti, con il plugin impostato su una stringa vuota, avrebbe dovuto essere effettivamente impostato su mysql_native_password, ma potrebbe essere confuso da un hash di password vuoto. Per maggiori dettagli, potete leggere la documentazione qui: https://dev.mysql.com/doc/refman/5.7/en/native-authentication-plugin.html

8
Advertisement
8
8
2016-04-28 21:27:58 +0000

Assicuratevi anche che il record necessario nella tabella user abbia il campo plugin vuoto (ci può essere, per esempio, "unix_socket").

Dalla versione 5.5.7 mysql ha vari plugin auth di supporto https://dev.mysql.com/doc/refman/5.6/en/authentication-plugins.html &003

Quindi se avete il campo plugin non vuoto allora la password verrebbe ignorata e ci sarebbe un avviso al registro errori di mysql (per me è /var/log/mysql/error.log):

[Warning] 'user' entry 'root@localhost' has both a password and an authentication plugin specified. The password will be ignored.

8
8
8
2016-01-22 23:08:02 +0000
grep 'temporary password' /var/log/mysqld.log
Sort date (newest date)

Potreste vedere qualcosa di simile;

[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
``` ```
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:

Assicurare l'installazione del server MySQL.

... 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)
``` &001 


Se vedete che c'è scritto 


&001 &001 


Guardate gli ultimi 10 minuti di [ questo video ](https://www.youtube.com/watch?v=L2m3BM28Mz0), vi insegna come si fa.
3
Advertisement
3
3
2017-11-10 20:13:46 +0000

Nel mio caso ho avuto una corruzione del database, dopo aver riavviato mysql su Debian il login di root era senza password. La soluzione è stata questa :

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'test';
``` &001 


Alcune altre risposte hanno anche menzionato il plugin nativo\_password ma questo è il modo in cui si può fare senza complicate manipolazioni. È così che deve essere cambiato.
3
3
3
2014-02-21 17:05:47 +0000

Prova:

mysql --no-defaults --force --user=root --host=localhost --database=mysql 
UPDATE user SET Password=PASSWORD('NEWPASSWORD') where USER='root';
FLUSH PRIVILEGES;
Advertisement