Create a MySQL User on Linux via Command Line
- Create a MySQL User on Linux via Command Line
- Grant Permissions to a MySQL User on Linux via Command Line
- Remove Permissions for a MySQL User on Linux via Command Line
Previous Series:
MySQL via Command Line 101: Basic Database Interaction
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.
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>
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.
Related Articles:
- How to Use Disk Quotas in Dedicated Linux Servers With Plesk
- Remove a MySQL User on Linux via Command Line
- Remove Permissions for a MySQL User on Linux via Command Line
- Grant Permissions to a MySQL User on Linux via Command Line
- Delete a MySQL or MariaDB Database via Command Line
- Select a MySQL Database on Linux via Command Line

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.
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
How to Install React.js on Windows
Read ArticleHow to Use Disk Quotas in Dedicated Linux Servers With Plesk
Read ArticleGuide on Connecting to Remote Servers Using SSH in Linux, Windows, or macOS Systems
Read ArticleNew User Tutorial: What is DNS?
Read ArticleDifference Between AlmaLinux and Rocky Linux
Read Article