I'm new to mysql and trying to get my head around user authentication for a db in mysql. The background is, in its simplest form, I am creating a document control DB. The principal table is called document control which contains a doc_id, name, date_added, blob etc.
The DB has a set of users, defined under the userid table, that contains general information such as the user_id, name, address, email, phone etc. To keep it simple for discussion, there is a relationship between the user_id and doc_id under table userdoclink. If the userid is associated with the doc_id, then that user has access to the doc_id recordset.
Tables summarised below:
**documentcontrol table**
doc_id
name
date_added
blob_data
**userid table**
user_id
name
address_line1
address_line2
email
phone
**userdoclink table**
user_id
doc_id
The question I have is, I understand mysql has a table called USER which contains the username and password and used for DB authentication as well setting privileges to table and recordsets. If each userid will have its own username and userid what would be the best practice of linking userid to the USER usernames?
Do I need to this or is there some other way of authenticating users to a DB via a custom user table?(very likely the email of the user will be username to access the DB). The only way I know is to authenticate through php as follows. Ultimately my intention is to have granular control on user access to certain recordsets only for UPDATE and READ within a table, any guidance on best way to proceed would be appreciated.
$con = mysql_connect("localhost", "username", "password") or die('Sorry, could not connect to server');
mysql_select_db("database", $con) or die('Sorry, could not connect to database');
user
to have direct access to yourMySQL database
(i.e. viaphpMyAdmin
) there is no need to do anything with MySQL'sUSER
table. Yourscript
, which connects to the database, needs to provide auser
-name, which must be a validMySQL USER
. All the other users of your PHP-Application need to be managed through your own script. – Mario Werner