0

I have tried to fix this since 3 hours now, I have grown so tired. All I want to do is ssh into a webserver, install mysql and use it. I have installed it on Ubuntu 16.04 via sudo apt-get install mysql-server. And no, I was not asked for a root password which so many people claim should happen on Ubuntu 16.04. Next I try sudo mysql -u root -p and then the prompt says "Enter password:". I have not ever set a password so I just hit enter and get Error 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO).

Frustration part / skippable: I found sooo many "solutions" where people say "Hey just start mysql and use this commend to authenticate the root user by this password" but it doesn't work, I cannot ACCESS mysql AT ALL, only ssh into the server works (hey, at least I'm there, yay). People have claimed I should use -h paramter, I've tried it all, using -h with 127.0.0.1 and the servers ip address, NOTHING works. I really hope someone who really KNOWS what he's talking about can step in and provide an in-depth explanation of the matter. Does it have to do with sockets? Is it just a password matter? Does it have to do with ssh? I cannot identify the problem and nobody takes the time to pass on knowledge instead of providing should-work-answers. How can it be so difficult to just install and use mysql, I can't believe I'm losing so much time on this :(

R-obert
  • 553
  • 4
  • 13

2 Answers2

2

I found the answer, thank you so much. More than a year ago I had installed mysql-server on that same server and I had set a password. It didn't come to my mind since I had purged everything. There should definitely be a warning like "do you want to use your old databases?" during installation. Just something, anything, that gives you a hint. I have closed roughly 100 tabs, all pointing in the wrong direction ("bind" settings, ssh tunnel, -h option, start a safe daemon and what not). So basically I have deleted /var/lib/mysql and everything was solved.

R-obert
  • 553
  • 4
  • 13
1

You should run 'mysql_secure_installation' for a fresh MySQL installation, this will tidy up a default installation and prompt you for a password for the MySQL root user.

Liam Gretton
  • 370
  • 1
  • 8
  • When I do `sudo mysql_secure_installation` it says "Enter password for user root:". What am I supposed to do here? I hit enter and I get "Error: Can't connect to local MySQL server through /var/run/mysqld/mysqld.sock (2)" – R-obert Apr 28 '20 at 14:04
  • update: I have purged `mysql-server` and `mysql-common` and deleted the mysql user via `userdel`, then did a fresh install and now /var/run/mysqld exists. So I did `sudo mysql_secure_installation` again. He says "Enter password for user root:" and I enter "fortheloveofgodplease" and then ... guess what: Access denied for user root@localhost ... banging my head against the wall :( – R-obert Apr 28 '20 at 14:23
  • 1
    It's not a fresh installation then, or the root password would be blank. See https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html especially section 'B.4.3.2.2 Resetting the Root Password: Unix and Unix-Like Systems' for instructions for resetting the mysql root user's password. – Liam Gretton Apr 29 '20 at 15:18