Granting rights on a database is done via a SQL script.
So, the first thing you have to do is to get the correct syntax.
You can find how to do that on
MySQL 5.7 Reference Manual / ... / GRANT Syntax[
^].
Then you have to get how to execute a MySQL query from a .NET assembly.
You will need:
- to download
Connector/Net[
^].
- to have a look at
MySQL Connector/Net Developer Guide[
^], and especially its
Chapter 5 Connector/Net Tutorials[
^].
Good work :)
[Update]
You have to define your user as 'username'@'computernameorip', not just 'username'.
In the present case, that would give
string computerNameOrIp = "%";
string login = string.Format("'{0}'@'{1}'", Userdd, computerNameOrIp);
query = string.Format("CREATE USER {0} IDENTIFIED BY '{1}'", login, Pass);
command = new MySqlCommand(query, connection001);
command.ExecuteNonQuery();
query = string.Format("GRANT SELECT, SHOW DATABASES ON database.* TO {0}", login);
command = new MySqlCommand(query, connection001);
command.ExecuteNonQuery();
In MySQL, there is one account per tuple (username, source).