Can't log into or get Mysql cmd line - mysql

I have a VPS running CentOS and have apache, php, mysql all installed. I was following a tutorial for installation and apparently did something wrong when setting up mysql (I believe something with setting user and password). Now whenever I try to get to the MySQL command line interface I receive this error.
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
I looked this up and got a few suggestions to try to bypass so I can reset the passwords. I've tried:
/etc/init.d/mysqld --skip-grant-tables
Which came up with the same error. I tried reinstalling by first removing mysql and then installing it again. Same Error appears. What else can I do?

(if U don't have anything in DB, remove mysqlDB - not installation, but DB files in /var/lib/mysql/ - backup it first!)
start this: shell# mysql_secure_installation
it will ask U to:
Set a root password. If you already have it
you’ll need to enter it for the remaining steps.
Remove anonymous users
Disable non-local root access
Remove the test database and access rules related to it
Reload privilege tables so the above changes are in effect
BR

Related

Problems with mysql on linux and also importing a dump from windows

I'm a beginner with linux (linux mint distro) and I have been trying to install mysql server and workbench. I couldn't connect to mysql server without sudo command. I tried to connect to the server on workbench, and Access denied for user 'root'#'localhost'. So I try to run workbench with sudo from terminal. Nothing. So I followed what somebody posted here on stackoverflow about changing my password auth mode to mysql_native_password, and was able to access SQL Server from workbench (only using sudo command).
So I try to import a dump which I made on windows mysql-workbench, and it gives me two errors:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
and
ERROR 1115 (42000) at line 24: Unknown character set: 'utf8_general_ci'
Nevertheless, the database seems to have been correctly imported (I can see values and columns and tables and they look alright).
What's happening and how to stop getting these access denied errors? I tried to search the web and there are different answers, but none of them seem to address first install. I don't see why wouldn't it work if I have made a pretty default install :(
Thanks a lot!
ps: I don't know if more specific info is needed. anonymous user was dropped after installation
Try resetting root password.
Step 1. Access to mysql using mysql -uroot
Step 2. Check the root user
select Host, User, authentication_string from mysql.user;
Step 3. Change password for root user
use mysql;
update user set authentication_string=password('NEWPASSWORD') where user='root';
flush privileges;
​quit;
Now try accessing to mysql using mysql -uroot -p using new password. If it works, use the credentials in workbench.

MySQL on Windows: Access Denied for User 'root'#'localhost' (using password: YES)

I'm using MySQL on windows (I wish I was using Mac, but due to some issues I'm using Bootcamp), and I've encountered a problem I think I've encountered before: the error that is written in the title. I think I might have solved this once before by erasing MySQL through the control panel and by erasing everything in the hidden folder, ProgramData, and MySQL from ProgramFiles, then reinstalling it. It is such a hassle and consumes a lot of time. It definitely isn't something I can do repeatedly to solve this problem if I get an error like this again and again.
The problem:
I simply ran this code on CMD after "cd"ing to the bin folder that contains mysql: mysql -u root -p PASSWORD but I get the error written in the title. Thus I can't login to mysql and run any lines to edit the database.
There are so many other topics like this in stackoverflow:
MySQL Error: : 'Access denied for user 'root'#'localhost'
Access Denied for User 'root'#'localhost' (using password: YES) - No Privileges?
https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
I tried implementing the solutions from the three links above. Many other advices advise to use the "sudo" command, which is not a windows command.
This is the line I get from implementing the solution given to me by dev.mysql.com (#3):
This is the line of code I ran in CMD:
mysqld --init-file=C:\\mysql-init.txt --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --console
This is the code I ran to implement the solution in link #2:
mysqld --skip-grant-tables --skip-networking --console
and the code I get back:
Things to note:
Each time, I get this line of code back from the console:
[Warning]...[Server] CA certificate ca.pem is self signed.
In the first picture, this is the "ERROR" I get from the console: [ERROR]...[Server] unknown variable 'defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini'
In the second picture, this is the "ERROR" I get from the console: [ERROR] TCP/IP --shared memory, or --named-pipe should be configured on NT OS
This is the line of code I would put in in mysql-init.txt: ALTER USER 'root'#'localhost' IDENTIFIED BY 'PASSWORDHERE';
or this: INSERT INTO mysql.user (Host, User, Password) VALUES ('%', 'root', password('YOURPASSWORD'));
GRANT ALL ON *.* TO 'root'#'%' WITH GRANT OPTION;
I installed MySQL through the installation wizard.
Q. How did I encounter this error?:
A. I was experimenting on a project for a back-end Spring Boot project that uses JPA and JDBC combined. I got errors telling me that no datasource could be configured.
Q.How did my root password get reset?
A.I think they got reset because of JPA's datasource autoconfiguration. I didn't touch any of mysql's settings myself. Something I did on Spring Boot and its automatic configuration to localhost must have reset the password.
I will say that uninstall your MySQL and again install it with a new instance but not like just uninstall it from the control panel that's why you are facing the same error every time. I already answered here in detail that how to remove properly so no error will come by creating a new instance.
For anyone encountering this issue after they initialized their mysql server with following command:
mysqld --initialize
Look out for the last output of the process, it should say something like this:
[Note] [MY-010454] [Server] A temporary password is generated for root#localhost: password12345
there is your temporary password to log in.

Access denied mysql server

I am trying to set up mysql on my Mac, but every time I type mysql on the command line I get:
ERROR 1045 (28000): Access denied for user 'arlet'#'localhost' (using
password: NO)
I type mysql -u root -p, and I get the same error.
I do not know if the server was set up correctly, because in the tutorial I am watching they activated it from preferences but in the installation package I got I did not have that option.
When I installed it I got a password and did not write it down, so I tried to reset it using the instructions in the manual Resetting the Root Password: Unix and Unix-Like Systems and no results. Please help.
Edit: Alright, I think it's best to delete mysql from my computer and reinstall it. I have tried sudo rm /usr/local/mysql and it does not work. How can I remove it?

MySQL not working with Laravel

This may be a noob question.
But I have tried everything, purging and reinstalling trying to reconfigure and the works.
For some reason my root that was set without a password on localhost is denying me access
I have tried to reset the root password using the command line but to no avail.
Does anybody know how to get this error to be fixed?
ERROR 1045 (28000): Access denied for user 'devin'#'localhost' (using password: NO)
I am using linux and ubuntu
Even though you set your root user to login without a password, this does not mean that user devin has been configured to login without a password.
Edit your .my.cnf file:
vi ~/.my.cnf
In the file which you see, hard code the password for user devin, save the file, then exit.
[client]
user=devin
password=your_password_goes_here
Then restart MySQL and devin should be able to login without using a password.
The following command should work to connect you to a database called my_db:
mysql --user=devin my_db

phpMyAdmin can't connect to the MySQL server

I am using MAMP.
It seems that when I tried making some changes with the passwords, I messed it up and now I can't access anything on phpMyAdmin.
I've tried to reinstall MAMP, but all I get is still the same error.
Does anybody know how to fix this?
UPDATE: Even in terminal I get the same error
/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
check your configuration file in MAMP, the password isn't defined
The reinstallation doesnt rewrite conf files
Try resetting your root password via the console. Instructions can be found here.
The instructions cover Windows and *Nix.
The reason why when you re-installed MAMP/WAMP/LAMP/MySQL etc and it doesn't remove the password is because it saves the config files, and when you remove MySQL it doesn't delete the config files relating to the passwords.
I've had this issue on Windows and Linux - But I can see it affects Mac's too.
Edit: I am assuming you have console access, because you mention MAMP - If you don't, try your host' control panel, it will have an option for Mysql there.