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';
Related
How do I grant permissions to users in MySQL?
This is the order in which I tried:
First, connect from EC2 SERVER to MYSQL CLIENT RDS.
After connecting, MYSQL created a user to give you permission.
An error occurs when giving the user permission.
My attempt:
mysql> CREATE USER 'injekim'#'125.128.63.112' IDENTIFIED BY 'k12345678!!';
Query OK, 0 rows affected (0.02 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'injekim'#'125.128.63.112' WITH GRANT OPTION;
ERROR 1045 (28000): Access denied for user 'root'#'%' (using password: YES)
ERROR 1045 (28000): Access denied for user 'root'#'%' (using password: YES)
Also, I found similar error information in stackoverflow, but I couldn't solve it.
MySQL ERROR 1045 (28000): Access denied for user 'bill'#'localhost' (using password: YES)
How can I authorize the user who created it?
It looks like you are not logged into the host machine. To use the root user, you should actually be logged into the machine (ssh or rdp) that is hosting the MySQL server.
Example, let's say I am setting at my Mac but need to give a new user access to a MySQL database that is running on a server with an IP address of 192.168.1.10. Assuming it's a Linux server I would ssh to the server from my Mac's terminal by running:
ssh myuser#192.168.1.10
You can now either:
Log into MySQL as root by running: mysql -u root -p (you will be prompted for the password)
Or,
You could become the root user. In my case, I would run the following:
sudo su. Now that you are the root user, you can log into MySQL by running:
mysql -p
If you need an example in a Windows environment, let me know. It will be the same basic idea, but using RDP instead of ssh. From your local machine, get a session on the actual server running MySQL and then log into MySQL as root from the server.
Ever since running as suggested: https://stackoverflow.com/a/50131831/3310334
alter user 'root'#'localhost' identified with mysql_native_password by 'Gzbz1H!fZ##LyF33IqP$rAS8H#0iNc4lK8l2Md#EHxJyFK2YgfQwiKxz*0#lykWvKdWzhxh6EYKu&6ZPp1#9$%YMPb6EfDPYf2h';
I can't access mysql anymore:
% mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
% sudo mysql
Password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
% mysql
ERROR 1045 (28000): Access denied for user 'theonlygusti'#'localhost' (using password: NO)
% sudo mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
I copy/paste my password exactly as I used to (and the password used to be the same).
In fact, I have noticed that any account that I "altered" as above I cannot log into through the terminal anymore, but they work from within Node.js using require('mysql') package.
How can I regain access to the root account without losing all my databases?
I just made the problem probably-worse by running
ALTER USER 'root'#'localhost' IDENTIFIED WITH caching_sha2_password BY 'Gzbz1H!fZ##LyF33IqP$rAS8H#0iNc4lK8l2Md#EHxJyFK2YgfQwiKxz*0#lykWvKdWzhxh6EYKu&6ZPp1#9$%YMPb6EfDPYf2h';
from inside javascript (after connecting as root).
It was successful.
Now I can't connect to root using JavaScript or the terminal.
I just tried following advice: https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
% cat init.sql
ALTER USER 'root'#'localhost' IDENTIFIED BY 'Gzbz1H!fZ##LyF33IqP$rAS8H#0iNc4lK8l2Md#EHxJyFK2YgfQwiKxz*0#lykWvKdWzhxh6EYKu&6ZPp1#9$%YMPb6EfDPYf2h';
% brew services stop mysql
% mysqld --init-file="$PWD/init.sql"
But I still can't connect by literally copy/pasting exactly the same password as above into the password prompt.
I have also tried the other reset method detailed in that link, using --skip-grant-tables:
% kill `cat /usr/local/var/mysql/theonlygustis-MacBook-Pro.pid`
% mysqld --skip-grant-tables
% mysql
> flush privileges;
> ALTER USER 'root'#'localhost' IDENTIFIED BY 'alter user 'root'#'localhost' identified with mysql_native_password by 'Gzbz1H!fZ##LyF33IqP$rAS8H#0iNc4lK8l2Md#EHxJyFK2YgfQwiKxz*0#lykWvKdWzhxh6EYKu&6ZPp1#9$%YMPb6EfDPYf2h';
> flush privileges;
> exit
% kill `cat /usr/local/var/mysql/theonlygustis-MacBook-Pro.pid`
% mysqld
% mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
It also doesn't work.
The preceding sections provide password-resetting instructions specifically for Windows and Unix and Unix-like systems. Alternatively, on any platform, you can reset the password using the mysql client (but this approach is less secure):
Stop the MySQL server if necessary, then restart it with the --skip-grant-tables option. This enables anyone to connect without a password and with all privileges, and disables account-management statements such as ALTER USER and SET PASSWORD. Because this is insecure, if the server is started with the --skip-grant-tables option, it also disables remote connections by enabling skip_networking.
Connect to the MySQL server using the mysql client; no password is necessary because the server was started with --skip-grant-tables:
shell> mysql //or sudo mysql
In the mysql client, tell the server to reload the grant tables so that account-management statements work:
mysql> FLUSH PRIVILEGES;
Then change the 'root'#'localhost' account password. Replace the password with the password that you want to use. To change the password for a root account with a different host name part, modify the instructions to use that host name.
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally (without the --skip-grant-tables option and without enabling the skip_networking system variable).
If does not help. Can see official page
https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
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.
I have a Linux EC2 instance which has MySQL server installed on it.
I can login with MySQL root with this command:
mysql -u root -p
For some reasons I created a user guest using following commands:
CREATE USER 'guest'#'%' IDENTIFIED BY 'passpass';
GRANT ALL PRIVILEGES ON * . * TO 'guest'#'%';
FLUSH PRIVILEGES;
Then I exit from root user and try to login with guest user:
mysql -u guest -p
entered the correct password and got this error:
ERROR 1045 (28000): Access denied for user 'guest'#'localhost' (using password: YES)
I even checked out for the anonymous user .
mysql> SELECT User, Host, Password FROM mysql.user WHERE User='';
Empty set (0.00 sec)
Kindly help. I am not able to connect to MySQL using guest user credentials
MYSQL AWS LINUX EC2 INSTANCE
I was trying to access mysql in AWS linux EC2 instance, but was getting the error:- Error: Access denied for user 'root'#'localhost'. After lot of searching I got the solution which worked for me.
So for mysql community server, the default password is randomly generated whenn you install.
Check /var/log/mysqld.log file, write vim /var/log/mysqld.log in terminal and search for the keyword "temporary password"- you will get the password.
Few configurations are required for mysql- sudo /usr/bin/mysql_secure_installation
it will ask for password then enter the "temporary password" collected earlier. and in the proceding steps question will be asked over there new password could be easily set. then can proceed with
mysql -u root -p.
try by Run the command
grant all on . to 'guest'#'%' identified by 'passpass';
flush privileges;
Thanks
I have installed Mysql on Mac os 10.7 using dmg installer, it got installed at location /usr/local/mysql I also installed MySQL.prefpane, where I can start and stop the server using services.
i am facing below problems.
mysql> create database test ;
ERROR 1044 (42000): Access denied for user ''#'localhost' to database 'ets'
same happens when I am trying to invoke mysql by using below command
./mysql -u root root
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Even when I created a connection using Eclipse to mysql db then also I got similar kind of exception.
Just want to know after installation do I need to make any further configuration related to user management and access privileges?
Try this,
./mysql -uroot -pPassword
To give the user all priviliges, execute this command:
GRANT ALL PRIVILEGES ON *.* TO root#'%' IDENTIFIED BY PASSWORD 'yourpassword' WITH GRANT OPTION
Also try
CREATE SCHEMA test;