There is phpmyadmin which give the possibility to secure all databases mysql with an password and username,but my need is to secure my one database,can I lock database mysql with password and username?
1 Answer
You can use the grant mysql command to secure a single database or even single ables as described here:
https://dev.mysql.com/doc/refman/5.1/en/grant.html
# 1. Create user
CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';
# 2. Grant right to user
GRANT ALL ON db1.* TO 'jeffrey'@'localhost';
GRANT SELECT ON db2.invoice TO 'jeffrey'@'localhost';
GRANT USAGE ON *.* TO 'jeffrey'@'localhost' WITH MAX_QUERIES_PER_HOUR 90;
Important pitfall: "localhost" may not be the same as 127.0.0.1. The host part of the user also depends on whether you connect to mysql via ip or via socket file.
It is usually good practice to use the minimum required permissions possible. (e.g: Only allow ALTER etc to the admin user)
A list of all perivileges can be found here:
https://dev.mysql.com/doc/refman/5.1/en/grant.html#grant-privileges