ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' when loading sql

1

Version: Server version: 10.1.32-MariaDB

I have trouble setting a password in mysql o mariadb use xampp 5.6

I install xampp I enter the console and with mysql -u root log me in.

Following different examples that I have seen through different web pages I have tried different ways to change the key, every time I have uninstalled I have installed the xampp again.

Test 1:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('clave');

Test 2:

# mysqladmin -u root -p password clave
Enter password:

PC-CASA@DESKTOP-11KK10F c:\xampp
# mysql -u root -pclave
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.1.32-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use mysql
Database changed
MariaDB [mysql]>

Trying either of the two ways if I access from the console or the workbench access perfectly, if I restart the mysql also accesses perfectly.

The problem comes when I load a *.sql with 2 databases, the load is done correctly I see the tables and everything, but when I restart the mysql when trying to access again it throws me the error:

  

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

Test

MariaDB [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'clave';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'USER 'root'@'localhost' IDENTIFIED BY 'clave'' at line 1
MariaDB [(none)]>
    
asked by nachfren 04.08.2018 в 16:09
source

2 answers

1

I tell you the following, I have in my computer equipment

  • MySQL 8
  • MariaDB 10.3
  • Although I do not work with XAMPP, I do the password change in this way

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'nuevacontraseña';
    
  • root or the equivalent of username that you have
  • localhost or the equivalent of your computer equipment
  • new password here you will enter the new password you want to assign be careful with the one you type
  • If the change happened successfully you should see a message similar to the following

      

    Query OK, 0 rows affected (0.20 sec)

    PROOF 1. MYSQL 8

    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'nuevopassword';
    Query OK, 0 rows affected (0.20 sec)
    

    PROOF 2. MariaDB 10.3

    MariaDB [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'nuevopassword';
    Query OK, 0 rows affected (0.001 sec)
    
      

    For both situations, once the change is made and you visualize said   message, close the terminal and try to log in but with the   new password that you establish

    Here I leave an official link to the MySQL documentation that explains it more in detail, however as I show you in the example also works for mariaDB

    link

        
    answered by 04.08.2018 / 16:30
    source
    0

    Try the following. Enter the root account of mariadb with mysql -u root -p. Enter your password, if you have one. Create the new user by entering:

    CREATE USER 'nombre_usuario'@'localhost' IDENTIFIED BY 'tu_contrasena';
    

    Now give permission to your user by entering:

    GRANT ALL PRIVILEGES ON *.* TO 'nombre_usuario'@'localhost';
    

    If you want me to have access to all the databases. Otherwise:

    GRANT ALL PRIVILEGES ON DB_NAME.* TO 'nombre_usuario'@'localhost';
    

    Sales of mariadb. You enter again with the new user: mysql -u username -p. Enter your password And you apply your sql.

        
    answered by 04.08.2018 в 17:11