Using the same credentials, and the root user having a localhost setting. I can login using the same credentials through a phpmyadmin interface. But not through the command line. I've setup the mysql, changed the password and all else. I should be good to go, however I I keep getting
ERROR 1045 (28000): Access denied for user 'root'#'localhost'
In the command line, this seems to also be the case with other as well. So I am not sure what the issue is.
Try using sudo mysql -u root command to access the mysql-server.
If that does not work create a new user through phpmyadmin :
CREATE USER 'username'#'localhost' IDENTIFIED BY 'password';
Then give it all the privileges :
GRANT ALL PRIVILEGES ON db_name. * TO 'username'#'localhost';
(if you want to give the user access to all the databases, replace db_name with an asterisk (*) )
then flush privileges to reload permissions :
FLUSH PRIVILEGES;
Then try to connect using that user through the command line
sudo mysql -u 'username' -p
You will be asked to type in the password.
Related
I'm running Homestead via Vagrant for a local Laravel install. I logged into Homestead via ssh (vagrant ssh), and connected to MySQL using the host localhost, user homestead, password secret. I was able to connect successfully, and running show databases; tells me there's an information_schema database in there. I thought all was well and I could create a new database for my Laravel project and get going.
Unfortunately, running CREATE DATABASE mynewdb; returned:
ERROR 1044 (42000): Access denied for user 'homestead'#'localhost' to database 'mynewdb'
I tried giving the homestead user some more privileges via:
GRANT ALL PRIVILEGES ON mynewdb.* TO 'homestead'#'localhost' WITH GRANT OPTION;
But get back a similar access denied message:
Access denied for user 'homestead'#'localhost' (using password: YES)
I tried a few other variations of that command, using '%' instead of 'localhost', for instance, but it seems like my homestead user just doesn't have the priviliges needed to administrate this db fully.
I thought I should be able to simple restart the mysql service with the --skip-grant-tables flag, and then login as homestead or root and have full privileges. This also failed to work:
vagrant#homestead:~$ sudo /etc/init.d/mysql stop
[....] Stopping mysql (via systemctl): mysql.servic[.ok
vagrant#homestead:~$ sudo /etc/init.d/mysql start --skip-grant-tables
[....] Starting mysql (via systemctl): mysql.servic[.ok
vagrant#homestead:~$ mysql -h localhost
ERROR 1045 (28000): Access denied for user 'vagrant'#'localhost' (using password: NO)
vagrant#homestead:~$ mysql -h localhost -u homestead
ERROR 1045 (28000): Access denied for user 'homestead'#'localhost' (using password: NO)
vagrant#homestead:~$ mysql -h localhost -u root
ERROR 1698 (28000): Access denied for user 'root'#'localhost'
vagrant#homestead:~$ mysql
ERROR 1045 (28000): Access denied for user 'vagrant'#'localhost' (using password: NO)
After those attempts, I logged in with homestead and secret, just to check and see if anything had changed:
vagrant#homestead:~$ mysql -h localhost -u homestead -p
mysql> create database mynewdb;
ERROR 1044 (42000): Access denied for user 'homestead'#'localhost' to database 'mynewdb'
Finally, I noticed in my homestead.yml file that there was an entry that looked like this:
databases:
- homestead
I modified this entry to:
databases:
- homestead
- mynewdb
And then rebooted the homestead VM:
vagrant halt
vagrant up
And then tried again to create the new datbase with the homestead MySQL user. None of this did anything, access is still completely denied for the homestead user trying to do just about anything.
Suggestions to gain access?
I didn't have the patience to try and solve this, as it clearly was not acting right at all. I finally just destroyed the Homestead VM and all its files after backing up my configuration, and reinstalled the machine. Booted it up, and how the homestead user has full access as it should. Not sure what the heck could have happened to it last time, but the lesson here is: Initializing new VM's is cheap, fighting with the wrong permissions is expensive.
If anyone has an explanation as to how I could have fixed this, I'll accept their answer. Otherwise, reinstalling Homestead seems to be the fastest solution.
To login into MySQL as root user, you can use:
mysql -u root -p
and then enter your MySQL password.
To login as another user, you will have to create that user first and grant him privileges.
Create the user using - change newuser to the username you want and password to your password of choice.
CREATE USER 'newuser'#'localhost' IDENTIFIED BY 'password';
Sadly, at this point newuser has no permissions to do anything with the databases.
Therefore the first stage is to grant the user the privileges to do 'things'.
To grant all privileges (select, create, delete, update, drop, etc) on all databases and tables, run:
GRANT ALL PRIVILEGES ON * . * TO 'newuser'#'localhost';
To grant a specific privilege on a particular database and table, just run:
GRANT [type of privilege] ON [database name].[table name] TO '[username]'#'localhost';
If you ever need to deny or revoke a certain privilege, just run:
REVOKE [type of permission] ON [database name].[table name] FROM '[username]'#'localhost';
I just created a user account for myself to access only the MariaDB database I just created ("publications") using XAMPP on a Windows 10 PC.
I did this by using the code at the end of this post.
I then try to sign into the database by using this path and command in the command prompt:
C:\xampp\mysql\bin\mysql -u steve -p
It then prompts me for a password, but when I enter the password I get the error
"ERROR 1045 (28000): Access denied for user 'steve'#'localhost' (using password: YES)"
I know the password is correct because I created it.
Note that this is NOT a root-level password; it should only work for the "publications" database.
Strangely, I can just bypass the password requirement by hitting "enter," but I want access to this database to be password-protected, but when I DO enter the password, I get the error!
Why am I getting this error? Do I need to reset my password? If so, how?
Thanks!
Code I entered:
GRANT ALL ON publications.* TO 'steve#localhost'
IDENTIFIED BY 'password';
After you entered command:
mysql>GRANT ALL ON publications.* TO 'steve'#'localhost';
Then flush:
mysql> FLUSH PRIVILEGES;
Try login again.
Note: make sure you created an user as follow command:
CREATE USER 'steve'#'localhost' IDENTIFIED BY 'passpass';
and note:
'steve#localhost'
or
'steve'#'localhost'
on GRANT ALL command
MySql is installed on a Ubuntu server.
I am running Windows 8.
Logging in through Putty. I can log in to database with both root and webadmin user accounts.
I can also log in through my browser, using <server ip address>/phpmyadmin
My problem is when I try to use command line to log in. I am trying that approach because I am developing a webpage to access the database on that server. It fails to connect, so I thought if command line works, the webpage will also work.
commandline:
mysql -u webadmin -p
or
mysql -u root -p
error 1045 (28000): access denied for user 'webadmin'#'localhost'
(using password: yes)
I added an iptables entry to allow mysql and that didn't work.
Also, the firewall on server is inactive.
You need to grant access to the database. You can read the documentation here: https://dev.mysql.com/doc/refman/5.1/en/grant.html
You can run the following (but be careful as it will leave your DB open)
GRANT ALL ON *.* TO 'root'#'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
That will allow root to connect from any IP and do any operations to the DB. If that still doesn't work, you might also need to run the following before the 2 lines above
CREATE USER 'root'#'%' IDENTIFIED BY PASSWORD '[your password]';
I just installed mysql on a mac and I can't seem to access any accounts from there.
I used the commands :
shell> mysql -u root -p
password:
and since I have not given one I let it go blank and I get an error saying incorrect password.
I can login using just
shell> mysql
buy I can't seem to be able to change passwords or even look at all the accounts in mysql.users.
I get the following error:
ERROR 1142 (42000): SELECT command denied to user ''#'localhost' for table 'users'
What do I do to resolve this issue and how do I use a software like sequel pro with the database?
Your problem seems, you dont have all the privileges for localhost#root, to get all the privileges run the below command.
mysql> grant all privileges on *.* to root#localhost identified by 'password' with grant option
in MySQL command prompt and you will have all the previleges to access the localhost as root.
use this command to set the password for MySQL
mysqladmin -u root password “newpassword”;
Example mysqladmin -u root password adhfhuef34;
You will also want to restart the database server after running this command
sudo /etc/init.d/mysql restart
If this Dint work, Try
$ mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("NEWPASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
Please forgive me for being a complete beginner:
I am trying to log into my very first mySQL database that I installed using easyPHP on my windows machine, using the cmd line. I am going to the \mysql\bin and entering the command:
mysql -u root
in order to log in, but I am getting the following message:
error 1045 (28000) access denied for user 'root'#'localhost' (using password: YES)
Why is it using the password "YES"? Shouldn't there be no password at all? Do I need to restart mySQL or something? If so, how do I do that? If it's relevant, I did try to create the database using phpmyadmin, but had a few problems entering columns and decided I'd be better off working from the command line so I could learn all the commands as I went along.
Please keep in mind that this is my first time ever trying to work with a database, so be kind to me!
To have mysql asking you for a password, you also need to specify the -p-option:
mysql -u root -p
When logging into MYSQL using the command line, you also have to specify the password if any. Your error message is telling you that the user "root" has a password attached to it. Not necessarily that the password is "YES" when you were installing easyPHP, it should have either provided you with a default password or allowed you to enter a password of your choosing.
According to the documentation of easyPHP:
[v1.6] My scripts worked perfectly with 1.5 but now I get this error : Warning: Forbidden access for user: 'user#localhost' (password: YES) when I want to connect to MySql.
Only the root user (without password) has the rights to connect to the database. Either modify your scripts to use it, or add the user you need (phpMyAdmin/users and privileges: See phpMyAdmin's documentation for more information).
mysql -u root -p
Now if you changed your root user password, you will need to specify that when prompted. Otherwise simply hit <Enter> on your keyboard.
If you FORGOT the password to root, and have changed it, you will have to subsequently reinstall easyPHP.
agk-hp:~/$mysql
ERROR 1045 (28000): Access denied for user 'greg'#'localhost' (using password: NO)
agk-hp:~/$sudo cat /etc/mysql/debian.cnf|grep password
password = t7753my3D2x4yfQm
agk-hp:~/$mysql -u debian-sys-maint -p
Enter password: {t7753my3D2x4yfQm}
Welcome to the MySQL monitor. Commands end with ; or \g.
mysql> use mysql;
mysql> grant all privileges on *.* to 'root'#'localhost';
mysql> grant all privileges on *.* to 'greg'#'localhost';
agk-hp:~/$mysql
mysql>
A modification for mysql- 5.7.10 on mac mac el capitan
sudo /usr/local/mysql/support-files/mysql.server stop
sudo mysqld_safe --skip-grant-tables
Now open new window/tab on terminal and type
"mysql -u root"
use mysql
update user set authentication_string=password('yourpassword') where user='root';