I am trying to connect MySQL Client to docker. I can connect just fine on the MySQL 8.0 Command Line Client, but when I try to connect to it from docker I get this error:
C:\Users\Bolin>docker exec -it mysql mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
I am on a window machine and I am trying to follow this tutorial
https://phoenixnap.com/kb/mysql-docker-container
hmm, looks like the issue is with privilege user for the database table,
Try to create a privileged user in your database named root. After that please check again
==========================================================================================
try these queries in your databse:
INSERT INTO mysql.user (Host, User, Password) VALUES ('%', 'root', password('YOURPASSWORD'));
GRANT ALL ON *.* TO 'root'#'%' WITH GRANT OPTION;
if the above code doesn't work try with the second
$mysql -u root mysql
$mysql> UPDATE user SET Password=PASSWORD('my_password') where USER='root';
$mysql> FLUSH PRIVILEGES;
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';
What is going on with the below? Why will mysql not let me in? I am using 5.6
root#ip-10-93-145-98:/home/ubuntu# echo "grant all privileges on *.* to 'really'#'%' identified by 'stupid';" | mysql -u root -ptest101
Warning: Using a password on the command line interface can be insecure.
root#ip-10-93-145-98:/home/ubuntu# mysql -u really -pstupid
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'really'#'localhost' (using password: YES)
Run a FLUSH PRIVILEGES after the GRANT ...
Try to login again after that.
I had installed lamp server in my Ubuntu 12.04 box when I tried to access MySQL I got this bug
ERROR 1045(28000) I tried many solution available in the internet nothing works.
These are all my bash scripts I had tried to access it :
root#sampath-codyowl:~# mysql -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
root#sampath-codyowl:~# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
First try this
mysql -h 127.0.0.1 -u root -p
If that worked then add root#localhost
GRANT ALL PRIVILEGES ON *.* TO root#localhost IDENTIFIED BY 'root-password' WITH GRANT OPTION;
Other reasons:
Check if there is a firewall blocking your mysql port(mysql default is 3306)
Make sure that the server has not been configured to ignore network connections. look for --skip-networking, or --bind-address flags.
Check this article : http://dev.mysql.com/doc/refman/5.0/en/access-denied.html
I create a new mysql user by using
CREATE USER 'new-username'#'localhost' IDENTIFIED BY 'new-password';
GRANT ALL ON *.* TO 'new-username'#'localhost' WITH GRANT OPTION;
And I can access mysql by
mysql -u new-username
But I got this error message when I try to access mysql using password
mysql -u new-username -p
error message
ERROR 1045 (28000): Access denied for user 'new-username'#'localhost' (using password: YES)
Something I am missing? Mysql version is Server version: 5.5.24-0ubuntu0.12.04.1 (Ubuntu)
Thanks
Here you required to pass password but you dont have entered any password.
CREATE USER 'new-username'#'localhost' IDENTIFIED BY 'new-password';
GRANT ALL ON *.* TO 'new-username'#'localhost' WITH GRANT OPTION;
mysql -u new-username -p new-password
And if you want to remove password from that then just use following line
SET PASSWORD FOR 'new-username'#'localhost' = ''