- Accessing MySQL on VB.NET using MySQL Connector/Net, Part 1: Introduction
- Accessing MySQL on VB.NET using MySQL Connector/Net, Part 2: Setup MySQL Server
- Accessing MySQL on VB.NET using MySQL Connector/Net, Part 3: Install Sample Database
- Accessing MySQL on VB.NET using MySQL Connector/Net, Part 4: Create & Grant MySQL User Account
- Accessing MySQL on VB.NET using MySQL Connector/Net, Part 5: Install MySQL Connector Net
- Accessing MySQL on VB.NET using MySQL Connector/Net, Part 6: Create Connection
- Accessing MySQL on VB.NET using MySQL Connector/Net, Part 7: Perform SQL Operations
- Accessing MySQL on VB.NET using MySQL Connector/Net, Part 8: Display Result on GUI
Create & Grant MySQL User Account
By default, the root account on MySQL Server has all privileges on every tables on MySQL Server but only localhost can have accessed (remote access is not allowed) and it is recommend to use other user account rather than root account to perform operations on MySQL Server (for security issue). Therefore, you should create a new user account on MySQL and grant at least privileges for the account as possible.
You can see index of this series at Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: IntroductionThis post, I’m going to show how to create a new user account “worldUser” on MySQL Server and grant privileges to the user account. Mostly usage privileges are SELECT, INSERT, DELETE and UPDATE. Also, I’ll allow remote connection from any host so that I can develop an application from remote PC to the database PC.
Note: If you are in development in a single environment, it’s OK to use root account. But Don’t in production.
Create New MySQL User Account
- On the Database PC, connect to MySQL Server. Open Command-line and type
mysql -u root -p
- To Create a User Account on MySQL Server, use this format:
CREATE USER username IDENTIFIED BY 'password'
- I’ll create MySQL User Account “worldUser” with password “worldpassword”. I use this account to connect to MySQL Server from remotely PC in later post.
CREATE USER worldUser IDENTIFIED BY 'worldpassword';
Grant Privileges on User Account
- To grant privileges on MySQL User Account, use this format:
GRANT privileges ON database.table TO 'username'@'host'
- I’m going to grant privileges on “worldUser” to allow SELECT, INSERT, UPDATE and DELETE on world database from any machine.
GRANT SELECT,INSERT,UPDATE,DELETE ON world.* TO 'worldUser'@'%';
- Another grant example. Grant SELECT privilege to mysql.proc on the certain user. This is not required to run, just an example.
GRANT SELECT ON mysql.proc TO 'worldUser'@'%';
On point 3 instead of “GRANT SELECT ON mysql.proc TO ‘worldUser’@’%’;” should read “GRANT SELECT ON PROCEDURE mysql.proc TO ‘worldUser’@’%’;”
Please remember that All users by default will have permission on all tables in the database…..
If you want selective table permissions you MUST
‘REVOKE’ permissions and reset specific..
The following set I use all of the time
When accounts are made permissions are set with a * and are NOT overriden by revoking against and setting permissions against specific tables.
YOU MUST revoke default set under *
Revoke SELECT,INSERT,UPDATE,DELETE ON database-name.* FROM ‘ac-name’
Revoke any set against specific table
Revoke SELECT,INSERT,UPDATE,DELETE ON database-name.TestTable FROM ‘ac-name’
Grant permissions set agianst specific table
Grant SELECT,INSERT,UPDATE,DELETE ON database-name.TestTable TO ‘ac-name’