mysqllinuxmysqladmin

Cannot set password for MySQL root user


I am trying to get MySQL running on my localhost. This never happened to me before, but upon installation sudo apt-get install mysql-server did not ask me for the initial password.

After searching for answers to "reset" my password and battling with directory permissions, i am currently at this state:

The mysqld_safe solution:

The system is Linux 4.15.0-48-generic #51-Ubuntu SMP.

The mysqladmin solution

If i run mysqladmin -u root password '0000' (without sudo), i get:

mysqladmin: connect to server at 'localhost' failed

error: 'Access denied for user 'root'@'localhost''

If i run it with sudo, i get:

mysqladmin: [Warning] Using a password on the command line interface can be insecure.

Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

This last one doesn't really tell me anything in regards of whether the password change happened or not; has it been refused or not (since it's a warning, not an error, i would assume it should go through), but in either case, trying to connect with 0000 still says "access denied".

Any advice on how to fix this is greatly appreciated.


Solution

  • I didn't quite solve the problems with mysql directly; However for myself, the acceptable solution was switching to a different database software, but it's still a MySQL system, and it got me up and running. So if anyone gets stuck on existing solutions not working like i did, maybe this comes in handy to get you on the road and finally writing code again.

    What i did was:

    1. Purged mysql off my system
    2. Manually deleted /etc/mysql and /var/lib/mysql (don't know if this step was necessary)
    3. apt clean, apt autoremove, apt update
    4. Installed mariadb
    5. Followed these instructions to rid myself of the timeout bug
    6. Used the mysqld_safe --skip-grant-tables method to create a new user with all privileges, since connecting with root always kept failing

    PHP + MariaDB now working again.