Salut,

Mariadb fraîchement installé, donc sans aucune conf. J'ai créé mon user aerya puis une DB aerya. Et depuis je me prends un put*** de ERROR 1045 (28000): Access denied for user 'aerya'@'localhost' (using password: YES)

Je suis pas un pro de SQL et je ne comprends pas mon erreur vu que je lui ai filé les droits pour tout :

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| aerya            |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> show grants for 'aerya'@'localhost';
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for aerya@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'aerya'@'localhost' IDENTIFIED BY PASSWORD 'sqssqsqsq' WITH GRANT OPTION |
| GRANT PROXY ON ''@'%' TO 'aerya'@'localhost' WITH GRANT OPTION                                                                          |
+----------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> 
Aerya a renommé le titre en Aide MySQL : Access denied for 'user'@'localhost'.

slt, par defaut il y a root comme user, cela marchait bien avant avec?

salut moi j'utilise ce petit script pour me crées un user +bdd

#! /bin/bash

newUser='dev'
newDbPassword='dev'
newDb='dev'
#host=localhost
host='%'

commands="CREATE DATABASE \`${newDb}\`;CREATE USER '${newUser}'@'${host}' IDENTIFIED BY '${newDbPassword}';GRANT USAGE ON *.* TO '${newUser}'@'${host}' IDENTIFIED BY '${newDbPassword}';GRANT ALL privileges ON \`${newDb}\`.*
TO '${newUser}'@'${host}';FLUSH PRIVILEGES;"

echo "${commands}" | /usr/bin/mysql -u root -p

    Ne fonctionne pas non plus avec root... tanguy Merci pour le script, que j'ai utilisé. Et là je pense que je vais juste balancer mon NUC par la fenêtre...
    ERROR 1045 (28000): Access denied for user 'aerya'@'localhost' (using password: YES)
    Alors que

    MariaDB [(none)]> show databases; 
    +--------------------+
    | Database           |
    +--------------------+
    | nouvelletable            |
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    4 rows in set (0.00 sec)
    
    MariaDB [(none)]> show grants for aerya@localhost;
    +----------------------------------------------------------------------------------------------------------------+
    | Grants for aerya@localhost                                                                                   |
    +----------------------------------------------------------------------------------------------------------------+
    | GRANT USAGE ON *.* TO 'aerya'@'localhost' IDENTIFIED BY PASSWORD 'xsxxsxsx' |
    | GRANT ALL PRIVILEGES ON `nouvelletable`.* TO 'aerya'@'localhost'                                                   |
    +----------------------------------------------------------------------------------------------------------------+
    2 rows in set (0.00 sec)
    
    MariaDB [(none)]> 

    On est bien d'accord qu'un sudo apt-get remove --purge mysql* ou maria* vire tout non ?

    Il faut d'abord que tu arrives à te connecter en root. Pour ça, tu dois resetter le password en suivant cette méthode : https://www.a2hosting.com/kb/developer-corner/mysql/reset-mysql-root-password (en gros, tu redémarres le service de façon minimale, qui permet une connexion locale, et de refaire le password).
    Une fois que c'est fait, tu peux te loguer en root sur ta base, et faire un reset du password de ton user

    ALTER USER 'userName'@'localhost' IDENTIFIED BY 'New-Password-Here';

    Une fois que tu as fait ça, ton user devrait pouvoir se connecter depuis la machine locale. S'il doit se connecter depuis une machine externe :

    ALTER USER 'userName'@'%' IDENTIFIED BY 'New-Password-Here';

    Tu peux remplacer % par une adresse ip spécifique.

    Je me connecte à MySQL avec root, justement, pour ça que je ne comprends pas. Le pwd root est donc bon. Et que ce soit avec root ou aerya ça me sort que j'ai les droits sur toutes les BDD et dès que je veux lancer une interaction ça plante.

      Hum je vais dire un truc débille mais tu lance bien le petit script avec sudo ?
      Parce que si je chmod et le lance il me fait le même type d'erreur ...

      On est bien d'accord qu'un sudo apt-get remove --purge mysql* ou maria* vire tout non ?

      Au dernière nouvelle oui 😛

      Après tes modifs de password, tu fais bien un flush privileges ?

      Bonjour à tous
      Aerya Tu as essayé mysql_secure_installation ?

      J'y suis même allé tout en root, pour te dire. Je flush les privilèges. Nan j'ai pas testé secure_install. Je regarde ça dans la journée 😉 Merci de vos pistes !

      Pas mieux...

      bash: mysql_secure_install: command not found
      root@rasthya:/home/aspen# mysql_secure_installapt install 
      bash: mysql_secure_installapt: command not found
      root@rasthya:/home/aspen# mysql_secure_installation       
      
      NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
            SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
      
      In order to log into MariaDB to secure it, we'll need the current
      password for the root user.  If you've just installed MariaDB, and
      you haven't set the root password yet, the password will be blank,
      so you should just press enter here.
      
      Enter current password for root (enter for none): 
      OK, successfully used password, moving on...
      
      Setting the root password ensures that nobody can log into the MariaDB
      root user without the proper authorisation.
      
      You already have a root password set, so you can safely answer 'n'.
      
      Change the root password? [Y/n] n
       ... skipping.
      
      By default, a MariaDB installation has an anonymous user, allowing anyone
      to log into MariaDB 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? [Y/n] 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? [Y/n] n
       ... skipping.
      
      By default, MariaDB 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? [Y/n] 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? [Y/n] y
       ... Success!
      
      Cleaning up...
      
      All done!  If you've completed all of the above steps, your MariaDB
      installation should now be secure.
      
      Thanks for using MariaDB
      Grants for root@%                                                                                   |
      +-----------------------------------------------------------------------------------------------------+
      | GRANT USAGE ON *.* TO 'root'@'%' IDENTIFIED BY PASSWORD 'sasasas' |
      | GRANT ALL PRIVILEGES ON `nouvelletable`.* TO 'root'@'%'   

      Et je me prends quand même un refus en voulant me connecter. Je précise qu'IPtables est vierge évidemment.

      slt, tu arretes bien ton server sql avant tout changement? et je ne comprends pas ce que vient faire '%''après ton @

      Attends attends... tu te connectes en local ? Si oui, il faut mettre les droits à root@'localhost' et pas root@'%' (localhost passe par un socket, et pas par du tcp/ip)

      Je tente local comme distant. Et oui SQL est stoppé puis relancé.

      Je suppose que tu n'as rien vu dans /var/log/mysql, ou dans journalctl -u mysql ?

      Nope. J'ai refais ma VM a neuf et ça fonctionne bien, en local comme en distant. Je ne sais pas ce que j'avais mal fait (#solitude).

      Merci de votre aide en tous cas..

      @Aerya je pense pas que ca soit toi, j'ai eu une fois cette mésaventure, j'ai réinstallé à l'identique avec les mêmes commandes et tout roule ... Le mystere des VM 😉

      Répondre…