If the database will be used by PHP scripts, add, update, delete, i.e. standard multiplayer site.

It is possible an example how to expose them, since creation of the new user?

  • one
    As I think and write. If you didn’t know the context, would you read your question? - Alexey Anufriev
  • one
    GRANT ALL ON database.* TO user@host - etki

1 answer 1

It is convenient to create a user using the CREATE USER statement.

 CREATE USER 'user'@'localhost' IDENTIFIED BY 'password'; 

Here a MySQL-user user with the password password , which will have access to the database only from the local machine. If the database is located on a separate host, then you should create a network user. It is better if you explicitly specify the domain from which the database will be accessed.

 CREATE USER 'user'@'php-domain.host.ru' IDENTIFIED BY 'password'; 

If this is not possible or there are too many such hosts, you can allow access from any hosts.

 CREATE USER 'user'@'%' IDENTIFIED BY 'password'; 

If you have not yet created a database for the user, you can create it using the CREATE DATABASE statement

 CREATE DATABASE IF NOT EXISTS `dbname` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; 

This creates a database called dbname and the default encoding UTF-8.

Now you can give user access rights to the dbname database

 GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `dbname`.* TO 'user'@'localhost'; 

With the last GRANT operator, we allowed CRUD operations (insert, delete, edit, read), as well as create, delete, modify, lock, and index tables.