I was getting an error trying to log in to mysql with mysql -u root -p , it always gave me the error "ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)". I'm on a Macbook Air running Yosemite.
So, I figured that I'd forgotten my password. It got so frustrating trying to reset it that I uninstalled mysql completely by sudo rming /usr/local/bin/mysql, and then reinstalling the dmg again from scratch. The installer gave me the gibberish temporary password, I tried logging in with it, and I got the same 1045 error that I've been getting all along. So maybe my first password wasn't wiped somehow . . . ?
I've tried this both with and without running mysqld in another terminal window, did not make a difference unfortunately. Any help on how I can just set the root password to whatever I want and log into mysql?
If you want to update a root password, then you need to use the following command:
$ mysqladmin -u root -p oldpassword newpassword
If you are trying to update the password for another user use:
$ mysqladmin -u user-name -p oldpassword newpassword
If you get a Access denied error it may be because you are not running the command as root.
To run a command as root add sudo to the beginning of the command.
For Example:
To update the password for the current, as root use:
$ sudo mysqladmin -u root -p oldpassword newpassword
To update the password for another user, as root use:
$ sudo mysqladmin -u user-name -p oldpassword newpassword
Also you might want to look at mysql_secure_installation, it will make your mysql installation more secure, it is recommended that you use it for production servers.
You first need to enter in your MySQL database : then copy and paste the following
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('SETYOURPASSWORDHERE');
Be sure your user is root
Related
I installed mysql in Ubuntu 20.04.
Problem -
Case 1: I have default root user. I can login using sudo mysql but cannot login using mysql -u root -p.
Case 2: I created another user 'local'. I can login using mysql -u local -p and by giving password I set. But problem is if I give wrong password, it still logs me in. I don't know why.
I followed this ERROR 1698 (28000): Access denied for user 'root'#'localhost'
but this didn't help me. I followed other topics too like creating new user for mysql etc.
I cannot access from workbench or from python script too.
Error : ERROR 1698 (28000): Access denied for user 'root'#'localhost'
Login to mysql using sudo mysql -u root
Give your su password and it will login without mysql password.
Run following commands:
USE mysql;
UPDATE user SET plugin='mysql_native_password' WHERE User='root';
FLUSH PRIVILEGES;
exit;
Restart:
sudo systemctl restart mysql.service
After that, run commands to secure MySQL server and create a new root password.
sudo mysql_secure_installation
When prompted, answer the following questions :
New password: Enter password
Re-enter new password:
Repeat password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y
Next time, type following command in terminal to login:
sudo mysql -u root -p
Then type mysql password you set recently to sign in.
Good Luck, this worked for after continuous wasting several hours on this thing and following tens of tutorials.
By doing this, I was finally able to establish connection in workbench and in my python scripts.
I was given a code repo which requires mysql in command line.
I am using Mac OS 10.11
First, I installed MySQL Community Server from http://dev.mysql.com/downloads/mysql/ and install it by running the PKG file.
After that, I opened System Preferences to start MySQL Server.
Then, I tried to execute
/usr/local/mysql/bin/mysql -uroot
and there is an error:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
How could I have mysql in command line?
Thanks,
Typically the command is:
/usr/local/mysql/bin/mysql -u root -p
which will prompt you for your root password (which might be blank unless you changed it)
You can also use:
/usr/local/mysql/bin/mysql -u root -p[password]
but keep in mind that password will be visible onscreen as you are typing it unlike the straight -p option that will hide your password as you type it when prompted.
Take a look at the options for mysql: https://dev.mysql.com/doc/refman/5.6/en/mysql-command-options.html
In your case, I'd try /usr/local/mysql/bin/mysql -u root -p then hit enter. mysql will prompt you for your password - type in in and hit enter again. If it's wrong mysql will let you know and then you'll have to go about resetting the mysql root password.
https://coolestguidesontheplanet.com/how-to-change-the-mysql-root-password/ is a reasonable set of instructions for doing that in OS X (may be out of date for your version of MySQL but the comments will help) but YMMV depending on where mysql was installed, etc...
Basically those instructions are:
sudo /usr/local/mysql/support-files/mysql.server stop
sudo mysqld_safe --skip-grant-tables
mysql -u root
ALTER USER 'root'#'localhost' IDENTIFIED by 'password';
FLUSH PRIVILEGES;
exit
sudo /usr/local/mysql/support-files/mysql.server start
Which
Stops mysql
Sets mysql to run without bothering with privileges
Opens a mysql prompt
Updates the root password to 'password' - you should use something else here.
"Cleans" passwords (some might say this is unnecessary)
Exits the mysql prompt
Starts mysql
That should allow you to run mysql -u root -p and use the new password set in #4.
I've just downloaded MySql using this tutorial after installing it before.
I've thought that it would solve my problems but, whenever I try to login into MySql via the terminal I'm prompted to enter the password though I've already logged in with the following command:
mysql -u user -p password
Here is what happening:
$> mysql -u user -p MYPASSWORD
Enter password:
And after I insert my password again...
$> mysql -u user -p MYPASSWORD
Enter password:
ERROR 1049 (42000): Unknown database 'MYPASSWORD'
I'd like to know if there's a solution to this weird problem.
The command is:
mysql -u user -ppassword
So in your case:
mysql -u user -p123456
By adding a space between -p and your password, you're actually setting the database to use, which is why you get the error unknown database.
The other solution would be:
mysql -u user -p
In that case, your password will be asked by the terminal. It is a bit more secure as your password does not stay in plain text in your terminal history. But if your password is 123456, I guess you're not too concerned by security ... ;)
Under normal circumstances, I would use:
mysql -uroot -p
Enter password:
you can try it.... ;)
I am trying to install openEMM on a Centos 6 VDS and have run into a snag. I am following the instructions on this page: http://www.roothelp.net/install-openemm-on-centos-6-x/. Everything has gone along fine until I reached the following commands:
service mysqld start
/usr/bin/mysql_secure_installation
cd /usr/share/doc/OpenEMM-2013/
mysqladmin -u root -p create openemm
The service starts fine, but when I run /usr/bin/mysql_secure_installation I get the following:
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, 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):
This is where the problems start. Apparently Plesk 11 does not create a root user account, using "admin" instead. None of my passwords work here, neither my actual SSH root password, my admin password, or any other password I've assigned. I even started mysql with this script to ensure I had the correct root password:
>UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
>FLUSH PRIVILEGES;
I tried this to ensure I had the correct password: /usr/local/psa/bin/admin --show-password
None of this has worked, and I am unable to run the command. How can I get around this? If I skip that command (GoDaddy support advised me that it was only configuring MySql, which is already installed with Plesk) and try to run
mysqladmin -u root -p create openemm
I am again asked for a root password and none work. I also tried this command instead, using the admin password but still had the same problem.
mysqladmin -u admin -p create openemm
I suspect I'll have to create a database called openemm through Plesk. Any ideas?
If you haven't set the mysql root password you can set it through the command
`$> mysqladmin -u root password "yourpassword"`
and if you want to change (or update) a root password, then you need to use the following command:
$> mysqladmin -u root -p'oldpassword' password newpass
Then you can create your database. In your case I think the mysql root password is just entered as the secure script asked you.
When I try to connect to the sql server and enter the following in command prompt:
shell> mysql --user=username--password=password db_name
I get error:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: Y
ES)
What does this error mean?
Looks like a space is missing between username and --password
If you don't know the root password, with Debian or Ubuntu, there is an easy way to reset it :
First, get the exact version of your server using
sudo dpkg --get-selections | grep 'mysql-server-'
Then, just use sudo dpkg-reconfigure mysql-server-5.x
(btw, replace 5.x with you real version number)
On a fresh install, the default root password is blank, so should be able to log in using just
mysql -u root
You should obviously add a root password after installation
mysqladmin -u root password [newpassword]
In most cases, you should also set up dedicated accounts with limited rights before working with a DB.
On Windows -
Search for services
Stop the service named MySQL[#] (in my case it was MySQL80).
Start the service again.
Open Command Prompt and type:
mysql [database name] -u [user name] -p
It worked for me when no other solutions worked. Hope this solves your issue as well.
It means your password is wrong or the account "root" has no access to the database on host "localhost".
Look at the right side bar. There are multiple questions equivalent to yours.