25th Anniversary Savings | 25% Off Dedicated Servers*Shop Now
25th Anniversary Savings | 25% Off VPS Hosting* †††Shop Now
Limited Inventory: High-Performance AMD-Powered Servers Now Available.* Shop Now >
Dedicated Hosting Deals | From $99/moShop Now

Create a MySQL User on Linux via Command Line

Posted on by Ronald Caldwell | Updated:
Reading Time: 2 minutes

MySQL is an open source, relational database management application primarily used on Linux as a component of the LAMP stack (Linux, Apache, MySQL, and PHP). When administering MySQL, an important operation is the creation of user accounts.

This article discusses how to create a MySQL user on Linux via the command line. The commands used should also work on later versions of MySQL on CentOS.

Prerequisites

  • Server running CentOS or AlmaLinux.
  • Root level access and log in as the root user.
  • Have access to a terminal.
  • Basic knowledge of the command line.
Create a MySQL User on Linux via Command Line

How to Create a MySQL User on Linux via Command Line

Step 1: Access the MySQL Server

Open a terminal to access the MySQL server from the command line using the following command. It specifies the root user with the -u flag. The -p flag makes MySQL prompt for a password. Enter your current password to complete the login.

mysql -u root -p

The system presents the below MySQL prompt. You can change a password for MySQL via the command line for the root or any other user in the database here.

mysql> 
Database Management Made Easy

Step 2: Create the MySQL User

Use the following command to create a user. For this tutorial, the username is testuser, and the password is test123test!. For your use, change these to your respective username and password.

mysql> CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'test123test!';

This single command creates the MySQL user. For the user to login and perform task in the MySQL databases, you need to grant them additional permissions, which is covered in another tutorial.

Step 3: Confirm the Created User

To confirm the newly created user, use the following command to view a full list of MySQL users, including the host with which they are associated.

SELECT User,Host FROM mysql.user;

Wrapping Up

MySQL is an excellent database management system capable of many database functions. Knowing how to create a MySQL user on Linux via the command line helps administrators keep track of and update database users. Existing Liquid Web customers with managed hosting services enjoy 24/7/365 support for these and other functions.

Liquid Web’s Linux-based VPS Hosting, Cloud Dedicated Servers, and Dedicated Servers come with MySQL and are updatable to MariaDB for those that prefer it. Contact our sales team today for more information.

Series Navigation
Next Article >>
Avatar for Ronald Caldwell

About the Author: Ronald Caldwell

Ron is a Technical Writer at Liquid Web working with the Marketing team. He has 9+ years of experience in Technology. He obtained an Associate of Science in Computer Science from Prairie State College in 2015. He is happily married to his high school sweetheart and lives in Michigan with her and their children.

Latest Articles

How to Install React.js on Windows

Read Article

How to Use Disk Quotas in Dedicated Linux Servers With Plesk

Read Article

Guide on Connecting to Remote Servers Using SSH in Linux, Windows, or macOS Systems

Read Article

New User Tutorial: What is DNS?

Read Article

Difference Between AlmaLinux and Rocky Linux

Read Article