I am Using Ubuntu 12.04 (precise) 64-bit Since i am new to Ubuntu i am having issue with grant
I'm using following cmd to grant in Ubuntu example
Sudo mysql -u root -p
create user username identified by 'pass'
grant all privilege on Db.* to username
if check grants using
show grants for username
| GRANT ALL PRIVILEGES ON . TO 'username' IDENTIFIED BY PASSWORD |
now if i login as user-name it will not ask for password it will directly login without password if i enter password for user it gives me error message:
sudo mysql -u username -p
ERROR 1045 (28000): Access denied for user user-name (using password: YES)
and after login if i give
show databases (it will not show any databases which is granted)
please guide me with an example
And also i would like to know tat if stored procedure is created in root how to get access
for other user even tho if i give grant for the particular stored procedure to other user
is there some thing to do with definer
You don't need to run sudo to just connect to MySQL as root.
Create a database:
$ mysqladmin create mydatabase -uroot -p
Connect as root or another user who can grant permissions
$ mysql -D mydatabase -uroot -p
Allow foouser to connect from this very same machine
mysql> grant all privileges on mydatabase.* to 'foouser'#'localhost' identified by 'pass';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
Connect as your new user:
$ mysql -D mydatabase -u foouser -p
Enter password: pass
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 129
Server version: 5.5.29-0ubuntu0.12.04.2 (Ubuntu)
Related
Somehow I lost root in mysql and I am trying to recover it.
I inserted root into the user table using the --skip-grant-tables option and then I ran
UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';
Then I started mysql regularly without --skip-grant-tables option
That’s what I see:
/usr/java/ep622_svn => mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.17 MySQL Community Server (GPL)
mysql> GRANT ALL ON *.* TO 'root'#'localhost';
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
This link helped:
https://dba.stackexchange.com/questions/97439/how-do-i-give-rootlocalhost-permission-to-grant-privileges-in-mysql
One needs to execute under running with --skip-grant-tables option:
UPDATE mysql.user SET
Select_priv='Y',Insert_priv='Y',Update_priv='Y',Delete_priv='Y',
Create_priv='Y',Drop_priv='Y',Reload_priv='Y',Shutdown_priv='Y',
Process_priv='Y',File_priv='Y',Grant_priv='Y',References_priv='Y',
Index_priv='Y',Alter_priv='Y',Show_db_priv='Y',Super_priv='Y',
Create_tmp_table_priv='Y',Lock_tables_priv='Y',Execute_priv='Y',
Repl_slave_priv='Y',Repl_client_priv='Y',Create_view_priv='Y',
Show_view_priv='Y',Create_routine_priv='Y',Alter_routine_priv='Y',
Create_user_priv='Y',Event_priv='Y',Trigger_priv='Y',
Create_tablespace_priv='Y'
WHERE user='root';
FLUSH PRIVILEGES;
The command:
mysql -u root -p
gives the error:
ERROR 1698 (28000): Access denied for user 'root'#'localhost'
But running sudo privileges, works:
sudo mysql -u root -p
Is it possible to get rid of the sudo requirement because it prevents me from opening the database in intellij? I tried the following as in the answer to this question Connect to local MySQL server without sudo:
sudo chmod -R 755 /var/lib/mysql/
which did not help. The above question has a different error thrown
Only the root user needs sudo requirement to login to mysql. I resolved this by creating a new user and granting access to the required databases:
CREATE USER 'newuser'#'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database_name.* TO 'newuser'#'localhost';
now newuser can login without sudo requirement:
mysql -u newuser -p
You need to change algorithm. Following work for me,
mysql > ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY '';
mysql > FLUSH PRIVILEGES;
You can use the same ROOT user, or a NEW_USER and remove the SUDO privileges. Below example shows how to remove connect using ROOT, without SUDO.
Connect to MY-SQL using SUDO
sudo mysql -u root
Delete the current Root User from the User Table
DROP USER 'root'#'localhost';
Create a new ROOT user (You can create a different user if needed)
CREATE USER 'root'#'%' IDENTIFIED BY '';
Grant permissions to new User (ROOT)
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' WITH GRANT OPTION;
Flush privileges, so that the Grant tables get reloaded immediately. (Why do we need to flush privileges?)
FLUSH PRIVILEGES;
Now it's all good. Just in case, check whether a new root user is created.
SELECT User,Host FROM mysql.user;
+------------------+-----------+
| User | Host |
+------------------+-----------+
| root | % |
| debian-sys-maint | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)
Exit mysql. (Press CTRL + Z). Connect to MySQL without SUDO
mysql -u root
Hope this will help!
first login to your mysql with sudo.
then use this code to change "plugin" coloumn value from "unix_socket" or "auth_socket" to "mysql_native_password" for root user.
UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin IN ('unix_socket', 'auth_socket');
FLUSH PRIVILEGES;
finally restart mysql service. that's it.
if you want more info, check this link
UPDATE:
In new versions of mysql or mariadb you can use :
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password USING PASSWORD('your-password');
FLUSH PRIVILEGES;
I have solved this problem using following commands.
CREATE USER 'username'#'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'username'#'localhost';
FLUSH PRIVILEGES;
Here,
username = any user name you like.
and password = any password you like.
You can use the below query:
GRANT ALL PRIVILEGES ON *.* TO 'username'#'localhost' IDENTIFIED BY 'password';
This query is enough.
This answer needs to be slightly adapted for mariaDB instead of mysql.
First login as root using sudo:
$ sudo mysql -uroot
Then alter the mariadb root user:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password USING PASSWORD('mypassword');
FLUSH PRIVILEGES;
From now on sudo is not longer needed:
$ mysql -uroot -p
Version used:
mysql Ver 15.1 Distrib 10.4.13-MariaDB, for osx10.15 (x86_64) using readline 5.1
Login to mysql with sudo:
sudo mysql -u root -p
After that Delete current root#localhost account:
~ MariaDB [(none)]> DROP USER 'root'#'localhost';
~ MariaDB [(none)]> CREATE USER 'root'#'localhost' IDENTIFIED BY 'password';
~ MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' WITH GRANT OPTION;
~ MariaDB [(none)]> FLUSH PRIVILEGES;
In the comment of the question you answer you referenced, it reads
Ok, just try to analyze all of the directories down in the path of the
socket file, they need to have o+rx and the sock file too (it's not a
good idea to make it modifiable by others).
You can also try to remove mysql.sock and then restart mysqld, the
file should be created by the daemon with proper privileges.
This seemed to work for this question(the one you said you looked at) so it may work for you as well
The error Message:
"ERROR 1698 (28000): Access denied for user 'root'#'localhost'"
means that the Server not allow the connect for this user and not that mysql cant access the socket.
try this to solve the problem:
Login in your DB
sudo mysql -u root -p
then make these modifications:
MariaDB []>use mysql;
MariaDB [mysql]>update user set plugin=' ' where User='root';
MariaDB [mysql]>flush privileges;
MariaDB [mysql]>exit
try login again without sudo
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
My root user has the following privileges:
mysql> SHOW GRANTS FOR root#'%';
+--------------------------------------------------------------------------------------------------------------+
| Grants for root#% |
+--------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' |
| GRANT ALL PRIVILEGES ON `bedrock`.* TO 'root'#'%' |
+--------------------------------------------------------------------------------------------------------------+
When I try to execute the following command, I receive the following error message:
mysqladmin root -pSOMEPASSWORD
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost' (using password: YES)'
Whilst I'm able to execute mysql command normally, I'm not able to do it to mysqld. What's the problem? Thanks.
You may have a user in your database without a password. Start mysql in safe mode then check to ensure none of your users have empty password fields. If you find one, either add a password or delete the user.
It may be that the password is incorrect and needs to be changed
For the improvement of the knowledge base:
The problem was in permissions and the command. It works when calling bin/mysqld_safe --user=mysql rather mysqladmin root -pSOMEPASSWORD. Note that user mysql had already got permissions throught chown -R and chgrp -R.
try this:
$ mysqladmin -u root -p password yourChosenPassword
Enter password:
and re-enter your same chosen password at the prompt, you will then be able to call mysqladmin from the command line:
$ mysqladmin -uroot -pyourChosenPassword [OPTIONS] command command....
Using MySQL 5.5 on Arch Linux, when I create a localhost user with a password and give it all privileges to all tables and then delete that user, I can still login as that user without typing in a password.
Steps to reproduce:
# mysql -u root -h localhost -p
Enter password: <root password>
mysql> create user 'test'#'localhost' identified by 'testing123';
mysql> grant all on *.* to 'test'#'localhost' identified by 'testing123';
mysql> select * from mysql.user where user='test';
1 row in set (0.00 sec)
mysql> exit
# mysql -u test -h localhost -p
Enter password: testing123
mysql> show databases;
mysql> exit
# mysql -u root -h localhost -p
Enter password: <root password>
mysql> delete from mysql.user where user='test';
Query OK, 1 row affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
mysql> select * from mysql.user where user='test';
Empty set (0.00 sec)
mysql> exit
# mysql -u test -h localhost
mysql> (Why?)
Not only that, but the "non-existing" test user can still exercise all of the same privileges. Major security problem. If I restart the server, it still lets me login without a password.
I finally figured out what was happening. By default, in the user table there is an anonymous user # localhost. This user is automatically matched with any attempted username and logged in as that anonymous user. Kind of strange, I know. To get rid of the anonymous user, login as root and perform the following command:
drop user ''#localhost;