Skip to content

How to grant user access to a database in MySQL command line?

Updated 1 min read

Updated: 28 September 2026 · Applies to: MariaDB 10.6 to 11.4 and MySQL 8

On a VPS or dedicated server, grant a user access to a database from the MySQL/MariaDB command line.

Steps

  1. Open the client as root: mysql (or mysql -u root -p).
  2. Create the user if it does not exist:
    CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'Strong-Password';
  3. Grant privileges on the database:
    GRANT ALL PRIVILEGES ON shopdb.* TO 'appuser'@'localhost';
  4. Check:
    SHOW GRANTS FOR 'appuser'@'localhost';

Note the quotes: the database name is written without quotes (or with backticks, `shopdb`.*), while the user and host are in single quotes.

Tip: Grant only what the application needs, for example SELECT, INSERT, UPDATE, DELETE, for read-and-write access without the right to change tables. On cPanel accounts, use Databases › Manage My Databases instead, so cPanel keeps track of the user.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket