I created user wanghao in MySQL and I want to create database in wanghao but an "access denied" error occurred. I want to create a database in user wanghao directly instead of using the following method.
create database exdb
grant all privileges on exdb.* to wanghao#localhost identified by 'wanghao'
You can do this like
GRANT ALL PRIVILEGES ON exdb.* To 'wanghao'#'hostname' IDENTIFIED BY 'password';
You must have the single quotes in there. 'localhost' tells MySQL you only want it from the same machine.
Related
I install phpMyAdmin on my subdomain for my clients to access their Databases, Because I can't give my Cpanel Login to them.
But my problem is when they need to create a new database, they can't do it from phpMyAdmin and they face this error
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY
'root';
And I try to create a DB using phpMyAdmin, login from cPanel but I had the same error.
No worry I can create and manage user and DB from cPanel, But the problem is I have to create a database myself when my client needs DBS.
So has I have an option for this, any type?
In your case, this error means the MySQL user does not have the required privilege to create a database. These are some options you could do:
Grant their user all privileges on all databases (not recommended):
GRANT ALL PRIVILEGES ON . TO 'sserver_sserver'#'localhost';
Create the database yourself and give their user all privileges on that specific database:
CREATE DATABASE my;
GRANT ALL PRIVILEGES ON my.* TO 'sserver_sserver'#'localhost';
Give their user all privileges to databases beginning with a certain prefix such as their business name which will allow them to create and work on as many databases as they need:
GRANT ALL PRIVILEGES ON 'businessname_%'.* TO 'sserver_sserver'#'localhost';
I want to have a non-root mysql user that can create another databases and users and grant access to that users to created databases. To do this as root I firstly created a user
CREATE USER asusi_admin#localhost IDENTIFIED BY '123';
Then I grant create user PRIVILEGE to this user
GRANT CREATE USER ON *.* TO 'asusi_admin'#localhost';
Then I grant all privileges to this user for the every database he creates
GRANT ALL PRIVILEGES ON `asusi\_%`.* TO 'asusi_admin'#'localhost WITH GRANT OPTION;
Now I'm flushing privileges
FLUSH PRIVILEGES;
Now I'm logging on to MySQL as newly created user asusi_admin and creating a new database
Now I'm creating a new database
CREATE DATABASE asusi_database;
Now I'm checking that I can use this database
USE asusi_database;
I can use this database, good
Now I'm creating a new user
CREATE USER 'asusi_user'#'localhost' IDENTIFIED '123';
Now I want to grant select privilege to the created user
GRANT select on `asusi_database`.* 'asusi_user'#'localhost'
And here I'm getting an error: 'Access denied for user 'asusi_admin'#'localhost' to database 'asusi_superdb'
Should I relogin as root and explicitly grant access to this database to a asusi_user
GRANT ALL PRIVILEGES ON `asusi_database`.* TO 'asusi_admin'#'localhost WITH GRANT OPTION;
and then relog in as asusi_admin and run the command again
GRANT select on `asusi_database`.* 'asusi_user'#'localhost'
this time it gives me no error and user asusi_user can read database asusi_database. Apparently MySQL wants me to explicitly grant access to the user asusi_admin for the every created database via root account. But I don't want to use the root account. I thought that after executing this command
GRANT ALL PRIVILEGES ON `asusi\_%`.* TO 'asusi_admin'#'localhost WITH GRANT OPTION;
user asusi_admin will be able to grant access to other users to the ecery database that stats with 'asusi_' prefix. May be I missed something or this behavior is designed to be that way?
It seems this is a confirmed bug, that was not fixed yet https://bugs.mysql.com/bug.php?id=75097, so nothing you can do right now with it.
I wanted to execute instructions to create and manipulate a data base so first I created a user as follow:
shell>cd program\xampp\mysql\bin;
shell>mysql -u root -h localhost
mariadb[(none)]>create user 'iw3htp#localhost'identified by 'sth';
grant all privileges on *.* to 'iw3htp#localhost';
flush privileges;
but when I want to execute instructions for creating and manipulating a database using source file or manually i face with error 1044 that says me "Access denied for user 'iw3htp'#'localhost'for database foo.
so whats wrong with this?
what I have to do?
A user access is defined by the user name and the host. Two parts.
With this:
create user 'iw3htp#localhost' ...
as a single string you have created a user
'iw3htp#localhost'#localhost
Change it to
create user 'iw3htp'#'localhost' identified by 'sth';
and
grant all privileges on *.* to 'iw3htp'#'localhost';
I want to create a new mysql user and database demo in my company. Here is the commands i input in the mysql.exe :
create user 'admin'#'localhost' identified by 'admin';
create database dem;
Everytime i have that response:
access denied for user ''#'localhost' to database.
Actually i refered to that similar question :
MySQL - Access denied for user
Can anyone help please ???
I would suggest creating the database first then you can create a user, and use the GRANT option to allow permissions to that user for whatever you find necessary. However, creating a user first then a database while it's able to "potentially" work, isn't the best practice with MySQL. So you want to effectively do the Steps as such:
Create Database
Create User
GRANT permissions
???
Profit
You have to GRANT access to admin for dem.
GRANT ALL PRIVILEGES ON *.* TO 'admin'#'%' WITH GRANT OPTION;
You may have to also GRANT the same for admin#localhost as well. IIRC if you ever logon remotely with admin you would inherit the base privileges unless otherwise GRANTed
You can find many answers HERE.
I have tried to create database on server by CREATE DATABASE cpi_mock but getting an error like #1044 - Access denied for user 'cpibetap'#'localhost' to database 'cpi_mock'. Then I try to execute SHOW GRANTS It gives me something like
Grants for cpibetap#localhost
GRANT USAGE ON *.* TO 'cpibetap'#'localhost' IDENTIFIED BY PASSWORD '<password>'
GRANT ALL PRIVILEGES ON `cpibetap\_%`.* TO 'cpibetap'#'localhost'
Can anyone tell me what is meaning of above lines? How can I create database on my server?
If the user only have USAGE privilege it does not have access to create the database.
You write "It gives me something like", can you paste the actual response?
The Grant all statements is for the user cpibetap_%, the _ requires a character and the username is only cpibetap thus not having any extra character.