Accessing MySQL on VB.NET using MySQL Connector/Net, Part IV: Create & Grant MySQL User Account
Programming, VB.NET February 28th, 2009Create & 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: Introduction
This 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.
Section
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'@'%';
Related post
- Accessing MySQL on VB.NET using MySQL Connector/Net, Part VI: Create Connection Create Connection After I have prepared many things for showing how to access MySQL Server using VB.NET. Let’s see what...
- Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: Introduction Introduction Here comes again, tutorial about programming to access a database server. This tutorial shows you how to use Microsoft...
- Accessing MySQL on VB.NET using MySQL Connector/Net, Part II: Setup MySQL Server Setup MySQL Server This section I’ll show how to setup MySQL Server on a database PC. You can see index...
- Accessing MySQL on VB.NET using MySQL Connector/Net, Part III: Install Sample Database Install Sample Database You can download example databases for MySQL at http://dev.mysql.com/doc (Scroll down to Example Databases section). By the...
- Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net Install MySQL Connector Net From last 4 parts, I have prepared MySQL Server with sample database. I’ve done on a...
Related posts:






March 31st, 2009 at 11:09 pm
On point 3 instead of “GRANT SELECT ON mysql.proc TO ‘worldUser’@'%’;” should read “GRANT SELECT ON PROCEDURE mysql.proc TO ‘worldUser’@'%’;”
January 3rd, 2011 at 7:16 pm
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’