How do I add a user to a MariaDB & MySQL database?

There are two ways to add a user to a MySQL database with Ultra Web Hosting:

 

Using phpMyAdmin

  1. Go to your Ultra Web Hosting control panel.
  2. Click on the "MySQL Databases" tab.
  3. Navigate to MySQL Users "Add New user".
  4. Enter a new Username and Password (twice).
  5. Click "Create user".
  6. In the "Users" section, click on the "Add User" button.
  7. Navigate to "Add User To Database".
  8. Select the new user in the drop down menu. 
  9. Select the corresponding database you want to add the user to.
  10. Click "Add".
  11. Check/click "All Privileges" (important).
  12. Click "Make Changes".

Using the command line via SSH

  1. Log in to your Linux web server via Secure Shell/SSH.
  2. Open the MySQL client program on the server in the /usr/bin directory.
  3. Type in the following syntax to create a new user:
CREATE USER 'username'@'hostname' IDENTIFIED BY 'password';
  • {username} is the name of the new user.
  • {hostname} is the hostname of the server where the database is located.
  • {password} is the password for the new user.
  1. Type in the following syntax to grant privileges to the new user:
GRANT {privileges} ON {databasename}.* TO 'username'@'hostname';
  • {privileges} is a comma-separated list of privileges. For example, to grant all privileges, you would type ALL PRIVILEGES.
  • {databasename} is the name of the database that you want to grant privileges to.
  1. Example:
GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost';

This will grant all privileges to the user my_user on the database my_database.

Once you have added the user, you can test to see if they have been granted the correct privileges by logging in to the database as the new user. For example, to log in as the user my_user on the database my_database, you would type the following command:

mysql -u my_user -p my_database


If you are able to log in and see the data in the database, then the user has been granted the correct privileges.


Which method you choose will depend on your preference and level of technical knowledge. If you are not familiar with the MySQL command line, then the control panel is a good option. It is a web-based interface that makes it easy to view and manage your MySQL databases.


Contact Ultra if you need help.
  • 873 Users Found This Useful

Was this answer helpful?

Related Articles

Test MySQL Connection

The following is a great way to verify a MySQL / MariaDB database connection issue. Create a file...

The MySQL server is currently offline admin bin Cpanel/cpmysql/DBCACHE: exit 11

The error message...  The MySQL server is currently offline admin bin Cpanel/cpmysql/DBCACHE:...

Error: SoftException in Application(dot)cpp:303 UID of script is small than min_uid

The error message "Error: SoftException in Application(dot)cpp:303 UID of script is small than...

How can I parse html as php?

Create an .htaccess file and upload it to the root of your public_html directory. Include the...

When trying to connect to MariaDB or MySQL you receive error 2003 Cannot connect to MySQL on xxxxxx on port 3306 10060

The error 2003 "Cannot connect to MySQL on xxxxxx on port 3306 10060" means that the MySQL...