I've created database, for example 'mydb'.
CREATE DATABASE mydb CHARACTER SET utf8 COLLATE utf8_bin;
CREATE USER 'myuser'@'%' IDENTIFIED BY PASSWORD '*HASH';
GRANT ALL ON mydb.* TO 'myuser'@'%';
GRANT ALL ON mydb TO 'myuser'@'%';
GRANT CREATE ON mydb TO 'myuser'@'%';
FLUSH PRIVILEGES;
Now i can login to database from everywhere, but can't create tables.
How to grant all privileges on that database and (in the future) tables. I can't create tables in 'mydb' database. I always get:
CREATE TABLE t (c CHAR(20) CHARACTER SET utf8 COLLATE utf8_bin);
ERROR 1142 (42000): CREATE command denied to user 'myuser'@'...' for table 't'
This is how I create my "Super User" privileges (although I would normally specify a host).
IMPORTANT NOTE
While this answer can solve the problem of access,
WITH GRANT OPTION
creates a MySQL user that can edit the permissions of other users.For security reasons, you should not use this type of user account for any process that the public will have access to (i.e. a website). It is recommended that you create a user with only database privileges for that kind of use.
This is old question but I don't think the accepted answer is safe. It's good for creating a super user but not good if you want to grant privileges on a single database.
%
seems to not cover socket communications, that thelocalhost
is for.WITH GRANT OPTION
is only good for the super user, otherwise it is usually a security risk.Hope this helps.
To access from remote server to mydb database only
To access from remote server to all databases.
1. Create the database
2. Create the username for the database db_name
3. Use the database
4. Finally you are in database db_name and then execute the commands like create , select and insert operations.
Works for privileges on schema :)
Optional: after
mypasswd
you can addWITH GRANT OPTION
I could able to make it work only by adding
GRANT OPTION
, without that always receive permission denied error