Home / code / sql

Users

This tutorial is create with MySQL in mind, but most command can be used on other SQL-type databases as well.

CREATE user and add grants

GRANT select,insert,update,delete,create,drop ON database.* TO 'username'@'localhost' IDENTIFIED BY 'password';
This is the command I use to create most of my users.

GRANT select,insert,update,delete,create,drop tells what right the user must have.
select is like just reading.
insert,update,delete allows too add, change and delete records.
create,drop is for creating and deleting new tables.

ON database.* on what database those rights apply, and the * means all tables in this database. but you could just put the name of a table.
TO 'username'@'localhost' the username is the username, and if the application is on the same server as the database, the localhost will do. But if you need to access it from somewhere else, you can add a ip-address or a range of ip-addresses. of-course security goes down with it. You might want to setup ssl too encrypt the traffic.
IDENTIFIED BY 'password'; password is the password to login. It will be stored encrypted.

Before any changed are active you need too FLUSH the privileges:

FLUSH PRIVILEGES;
or you can restart the MySQL-daemon. /etc/init.d/mysql restart

 

TOP

Latest script:

 

Books: