How to Create a MySQL Database Using CLI & cPanel Updated on February 21, 2025 by InMotion Hosting Contributor 2 Minutes, 49 Seconds to Read If you need to create a database for your website there are multiple ways to do it. In this guide, you can learn how to create a MySQL database using two methods: the command line interface (CLI) and cPanel MySQL Database Wizard. You can then being using the database or connect your software. Create a MySQL Database Using CLI If you are running a Linux server with MySQL but no cPanel, you can simply use the terminal to create a MySQL database, database user, and password, as well as, assign all privileges to the user for the database. Don’t have time to read the article? Watch our walk-through video. IMPORTANT: This guide is intended for use with our Cloud Server Hosting and other hosting plans that do not include cPanel. If your server includes cPanel, you should follow our guide on How to Create a MySQL Database Using the cPanel API. SSH into your server as root. Log into MySQL as root:mysql -u root Create a new database user: GRANT ALL PRIVILEGES ON *.* TO 'db_user'@'localhost' IDENTIFIED BY 'P@s$w0rd123!'; NOTE: Be sure to modify db_user with the actual name, you would like to give the database user, as well as, P@s$w0rd123! with the password to be given to the user. Log out of MySQL by typing: \q. Log in as the new database user you just created: mysql -u db_user -p NOTE: Be sure to modify db_user with the actual database user name. Then, type the new database user’s password and press Enter. Create a new database by running the following command and specifying the name of the database: CREATE DATABASE db_name; NOTE: Be sure to modify db_name with the actual name you would like to give the database. How to Create a MySQL Database in cPanel Don’t have time to read the full guide? Watch our walk-through video. When you create a database, many users are unaware that there are several other tasks that you need to do as well. The new database creation process actually involves: Creating a database Creating a database user Giving your database user access to work with your database Luckily for us, cPanel includes a MySQL Database Wizard that walks you through each of these steps. Creating a Database in cPanel Using the MySQL Database Wizard Log into your cPanel. Click the MySQL Database Wizard under the Databases heading. Next to New Database enter a name for your database and click Next Step.WARNING: If you receive an error message regarding the limited number of databases available, you may consider upgrading your shared server space. Enter a username, enter a password twice, then click the Create User button. On the next page, you’ll assign privileges for the user to the database. Check the box next to All Privileges and then click Next Step. You can also select specific privileges instead.You are finished when you see a message stating that the user was added to the database. Congratulations! Now, you know how to create a MySQL database from the command line and using cPanel. Want to learn more about database management? Check out official MySQL documentation or our guide on How to Import MySQL Databases in Command Line. Scalable VPS Infrastructure, Fully Managed When shared hosting can't handle your traffic, VPS delivers dedicated resources that scale with demand. Our team manages the technical complexity while you manage your business. NVMe Storage High-Availability Ironclad Security Premium Support VPS Hosting Share this Article InMotion Hosting Contributor Content Writer InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals! More Articles by InMotion Hosting Related Articles Database Optimization: Tips Using MySQL Tuner How to Check and Repair a Database in phpMyAdmin Create a blank database How to Create a MySQL Database Using CLI & cPanel How to Connect to a Database with MySQL Workbench Setting up a Remote MySQL Database Connection MySQL 1064 Error: You have an error in your SQL syntax Using MySQLi to INSERT Data into a Database How to get PostgreSQL on a VPS / Dedicated Server What is MariaDB?
Yeah, but you don’t restrict this user to a database! You grant them all privileges to EVERYTHING. This is rather dangerous….
Thanks for your feedback. For more information on granting and revoking permissions, here is a helpful link to the official MySQL documentation on the GRANT statement.
GRANT ALL PRIVILEGES ON *.* TO ‘db_user’@’localhost’ ? Does it not basically make the new user a root user, meaning access to everything? That would be very bad