When I create a admin user with:
GRANT ALL ON * TO my_name#localhost IDENTIFIED BY 'my_passwd' WITH GRANT OPTION
I received the error message "ERROR 1046 (3D000): No database selected".
You should be saying it like below by qualifying it with database name. Check MySQL Documentation for more information.
GRANT ALL ON db_name.*
So for your case,
GRANT ALL ON db1.* TO my_name#localhost IDENTIFIED BY 'my_passwd'
WITH GRANT OPTION;
Related
I tried:
GRANT ALL PRIVILEGES ON someuser_.* TO 'someuser'#'%';
but it allows me creating only one database someuser_
I want to allow user someuser for all the database-name starts with someuser_ [like cPanel]
I tired:
GRANT ALL PRIVILEGES ON someuser_*.* TO 'someuser'#'%';
but it returns me:
ERROR 1046 (3D000): No database selected
I am able to create new databases through the root account. but I need to create new databases using a new user that I have created.
Here is error I'm getting when trying to create a database using the new user
ERROR 1044 (42000): Access denied for user 'user'#'localhost' to database 'new_db'
How can I grant permissions to "user" so it create any number of new databases?
Update:
This is also what I tried:
mysql> grant all privileges on db.* to 'user'#'%' with create;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'create option' at line 1
mysql>
PHP example:
$con = new mysqli("...","...","..."); // CONNECT TO DB WITH ROOT USER
mysqli_query($con, "GRANT ALL PRIVILEGES ON newdb.* TO 'user'#'%' WITH GRANT OPTION");
Command line example:
login with root user, and use this:
GRANT ALL PRIVILEGES ON newdb.* TO 'user'#'%' WITH GRANT OPTION;
This will create a user how is permitted to create new databases (but will give him also all the permissions to do bad stuff, so handle it wise...).
This is for create only:
GRANT CREATE ON *.* TO 'newuser'#'%' IDENTIFIED BY 'password'
I am trying to create view of a table by making use of the following command "create view vendor_view.v as select * from vendor;". But I get a message as
ERROR 1142: CREATE VIEW command denied to user 'myuser'#'%' for table 'v'
I tried to GRANT privileges to the user using the command
GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'#'%' WITH GRANT OPTION;
But again I get the error as
ERROR 1044: Access denied for user 'myuser'#'%' to database 'mydb'
Could anyone suggest as to how can I grant privileges?
I am creating a user app_root identified by a password with limited permission. This user should only be able to create a database with prefix, create a new user, and grant permission to new user to access the database. So this is what I am doing.
CREATE USER app_root#localhost IDENTIFIED BY 'password';
GRANT CREATE USER ON *.* TO app_root#localhost WITH GRANT OPTION;
GRANT CREATE ON `myapp\_%`.* TO app_root#localhost WITH GRANT OPTION;
FLUSH PRIVILEGES;
The user is duly created. Now I log in to mysql with app_root user and execute following:
CREATE DATABASE test;
It fails as expected because name of database does not contain myapp_ prefix.
CREATE DATABASE myapp_test;
CREATE USER myapp_test#localhost IDENTIFIED BY 'ABC';
Both database and user are successfully created. But if I execute grant statement, error occurs.
GRANT ALL PRIVILEGES ON myapp_test.* TO myapp_test#localhost;
It generates ERROR 1044 (42000): Access denied for user 'app_root'#'localhost' to database 'myapp_test'. Could anyone please tell me what is wrong with my approach?
MySQL Version - Server version: 5.5.37-0ubuntu0.14.04.1 (Ubuntu)
Edit - As suggested, I granted all privileges to app_root user. But it still does not change anything.
GRANT ALL ON `myapp\_%`.* TO app_root#localhost WITH GRANT OPTION;
FLUSH PRIVILEGES;
grant all privileges on 'bbs' to 'userone'#'localhost' IDENTIFIED BY PASSWORD 'user2012';
It shows ERROR 1064 (42000): You have an error in your SQL syntax; check the manual
I want to add a user userone and grant all privileges to the database bbs.
How to correct it?
You need to include an indicator for the tables in the database you want to grant the privilege. Change the query:
grant all privileges on bbs.* to 'userone'#'localhost' IDENTIFIED BY PASSWORD 'user2012';
to grant it for all the tables in the 'bbs' database.
Leave the ' at the table name:
grant all privileges on bbs to 'userone'#'localhost' IDENTIFIED BY PASSWORD 'user2012';
grant all privileges on 'bbs.*' to 'userone'#'localhost' identified by ‘user2012’;