Locking is a concurrency control mechanism used by databases to control simultaneous access to data by multiple users. There are different types of locks like page, table, and row locks that can be applied at various levels of granularity. Locks prevent inconsistent data access and lost updates by blocking other transactions from modifying the same data that a transaction is currently accessing or modifying until that transaction is complete. The database's lock manager monitors all locks to detect and resolve any lock conflicts or deadlocks that may occur between transactions.