{"id":1609,"date":"2026-09-03T16:58:58","date_gmt":"2026-09-03T11:28:58","guid":{"rendered":"https:\/\/cpanelfree.com\/blog\/how-to-create-mysql-database-user-cpanel\/"},"modified":"2026-09-03T17:02:06","modified_gmt":"2026-09-03T11:32:06","slug":"how-to-create-mysql-database-user-cpanel","status":"publish","type":"post","link":"https:\/\/cpanelfree.com\/blog\/how-to-create-mysql-database-user-cpanel\/","title":{"rendered":"How to Create MySQL Database and User with Full Privileges in cPanel"},"content":{"rendered":"<div style=\"background-color: #f8fafc;border-left: 4px solid #a855f7;padding: 20px;border-radius: 6px;margin-bottom: 25px\">\n<p style=\"margin: 0;font-size: 16px;color: #1e293b\">\n        <strong>Quick Answer:<\/strong> To create a MySQL database and user in cPanel: <strong>1)<\/strong> Navigate to <strong>MySQL Databases<\/strong> (or <em>MySQL Database Wizard<\/em>), <strong>2)<\/strong> Enter your database name and click <em>Create Database<\/em>, <strong>3)<\/strong> Create a new MySQL user with a strong password, and <strong>4)<\/strong> Under <em>Add User to Database<\/em>, select your user and database, check <strong>ALL PRIVILEGES<\/strong>, and click <em>Make Changes<\/em>.\n    <\/p>\n<\/div>\n<h2>Understanding the 3 Core Components of cPanel Databases<\/h2>\n<p>When hosting dynamic web applications (WordPress, Laravel, Node.js, Python), cPanel requires 3 distinct elements to establish secure database communication:<\/p>\n<ul style=\"padding-left: 20px;line-height: 1.8\">\n<li><strong>1. Database:<\/strong> The storage container housing your tables, columns, and data rows.<\/li>\n<li><strong>2. Database User:<\/strong> A secure account with authentication credentials.<\/li>\n<li><strong>3. User Privileges (GRANT):<\/strong> The explicit permissions determining whether the user can <code>SELECT<\/code>, <code>INSERT<\/code>, <code>UPDATE<\/code>, <code>DELETE<\/code>, or <code>DROP<\/code> tables.<\/li>\n<\/ul>\n<h2>Step-by-Step Tutorial: Creating Database and User in cPanel<\/h2>\n<h3>Step 1: Create a New Database<\/h3>\n<ol style=\"padding-left: 20px;line-height: 1.8\">\n<li>Log in to your <a href=\"https:\/\/cpanelfree.com\/\">CpanelFree<\/a> dashboard.<\/li>\n<li>Under the <strong>Databases<\/strong> category, click <strong>MySQL Databases<\/strong>.<\/li>\n<li>Under <em>Create New Database<\/em>, enter your desired database name (e.g. <code>appdb<\/code>).<\/li>\n<li>Click <strong>Create Database<\/strong>. Note the full database name including your account prefix (e.g. <code>username_appdb<\/code>).<\/li>\n<\/ol>\n<h3>Step 2: Create a MySQL Database User<\/h3>\n<ol style=\"padding-left: 20px;line-height: 1.8\">\n<li>Scroll down to the <strong>MySQL Users &#8211; Add New User<\/strong> section.<\/li>\n<li>Enter a username (e.g. <code>dbadmin<\/code>).<\/li>\n<li>Use the <strong>Password Generator<\/strong> to generate a strong 18-character password. Copy and save it securely.<\/li>\n<li>Click <strong>Create User<\/strong>.<\/li>\n<\/ol>\n<h3>Step 3: Assign User to Database with Full Privileges<\/h3>\n<ol style=\"padding-left: 20px;line-height: 1.8\">\n<li>Scroll down to <strong>Add User To Database<\/strong>.<\/li>\n<li>Select your newly created user from the <em>User<\/em> dropdown and your database from the <em>Database<\/em> dropdown.<\/li>\n<li>Click <strong>Add<\/strong>.<\/li>\n<li>On the Manage User Privileges screen, check the <strong>ALL PRIVILEGES<\/strong> box.<\/li>\n<li>Click <strong>Make Changes<\/strong>.<\/li>\n<\/ol>\n<h2>Connecting Your PHP or WordPress Application<\/h2>\n<p>Use your newly created credentials to configure your application connection string:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">\/\/ PHP PDO Database Connection Example\n$host = 'localhost';\n$db   = 'username_appdb';\n$user = 'username_dbadmin';\n$pass = 'YourSecurePassword123!';\n$charset = 'utf8mb4';\n\n$dsn = \"mysql:host=$host;dbname=$db;charset=$charset\";\n$pdo = new PDO($dsn, $user, $pass, [\n    PDO::ATTR_ERRMODE =&gt; PDO::ERRMODE_EXCEPTION,\n    PDO::ATTR_DEFAULT_FETCH_MODE =&gt; PDO::FETCH_ASSOC,\n]);<\/pre>\n<div style=\"background-color: #f8fafc;border: 1px solid #e2e8f0;border-left: 4px solid #0ea5e9;padding: 20px;border-radius: 8px;margin: 30px 0\">\n<h3 style=\"margin-top: 0;color: #0f172a;font-size: 18px;display: flex;align-items: center\">\n        <span style=\"margin-right: 8px\">\ud83d\udd17<\/span> Recommended Related Technical Guides:<br \/>\n    <\/h3>\n<ul style=\"margin: 10px 0 0 0;padding-left: 20px;line-height: 1.8\">\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-increase-phpmyadmin-upload-file-size-limit\/\" style=\"color: #0284c7;text-decoration: none;font-weight: 600\">How to Increase phpMyAdmin Upload File Size Limit<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-fix-error-establishing-database-connection-wordpress\/\" style=\"color: #0284c7;text-decoration: none;font-weight: 600\">How to Fix Error Establishing a Database Connection in WordPress<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-export-import-large-mysql-database-command-line\/\" style=\"color: #0284c7;text-decoration: none;font-weight: 600\">How to Export &amp; Import Large MySQL Databases via CLI<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/#plans\" style=\"color: #0284c7;text-decoration: none;font-weight: 600\">Explore $0 Free cPanel Web Hosting Plans<\/a><\/li>\n<\/ul>\n<\/div>\n<h2>Managing Granular Database Privileges and Security Restrictions<\/h2>\n<p>While <strong>ALL PRIVILEGES<\/strong> is required for WordPress to execute core updates, plugin installations, and schema migrations, custom microservices and read-only reporting dashboards should be restricted to minimal privilege sets:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\"># Grant Read-Only Analytical Access\nGRANT SELECT ON username_appdb.* TO 'username_readonly'@'localhost';\n\n# Grant Standard CRUD Privileges (No Schema Alteration)\nGRANT SELECT, INSERT, UPDATE, DELETE ON username_appdb.* TO 'username_appuser'@'localhost';\nFLUSH PRIVILEGES;<\/pre>\n<h2>Enabling Remote Database Access in cPanel (Remote MySQL)<\/h2>\n<p>If you run desktop database management tools (like DBeaver, TablePlus, or Navicat) or host a frontend application on an external server, authorize external IP addresses in cPanel under <strong>Remote MySQL<\/strong> by adding your public IP address (or <code>%<\/code> for wildcard access, paired with strong SSL encryption).<\/p>\n<h2>Best Practices for Database Security in Production Environments<\/h2>\n<ul style=\"padding-left: 20px;line-height: 1.8\">\n<li>\ud83d\udd12 <strong>Never Use Root for Applications:<\/strong> Always create dedicated, isolated database users for each application rather than reusing the root account.<\/li>\n<li>\ud83d\udd12 <strong>Enforce Strong Alphanumeric Passwords:<\/strong> Generate random 24-character passwords combining upper\/lowercase, numbers, and symbols.<\/li>\n<li>\ud83d\udd12 <strong>Restrict Host Binding:<\/strong> Ensure users are bound strictly to <code>localhost<\/code> (or specific trusted IP subnets) rather than the open wildcard (<code>%<\/code>).<\/li>\n<li>\ud83d\udd12 <strong>Disable Remote MySQL if Unused:<\/strong> Keep external port 3306 closed in your server firewall unless remote access is strictly required.<\/li>\n<\/ul>\n<h2>Automated Database Provisioning via cPanel UAPI Command Line<\/h2>\n<p>Sysadmins and developers can automate database and user creation in cPanel without clicking through the GUI using cPanel UAPI:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\"># Create database via cPanel CLI\nuapi Mysql create_database name=username_customdb\n\n# Create database user\nuapi Mysql create_user name=username_customuser password='SecurePassword123!'\n\n# Grant full privileges\nuapi Mysql set_privileges_on_database user=username_customuser database=username_customdb privileges=ALL%20PRIVILEGES<\/pre>\n<div style=\"background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);border: 1px solid #334155;border-radius: 12px;padding: 25px;margin: 30px 0;text-align: center\">\n<h3 style=\"color: #38bdf8;margin-top: 0;font-size: 20px\">Unlimited MySQL Databases on CpanelFree<\/h3>\n<p style=\"color: #94a3b8;font-size: 14px;line-height: 1.6;max-width: 600px;margin: 0 auto 15px\">\n        Create unlimited MySQL databases, manage tables with phpMyAdmin, and enjoy NVMe SSD hosting at 100% zero cost on <strong>CpanelFree<\/strong>.\n    <\/p>\n<p>    <a href=\"https:\/\/cpanelfree.com\/#plans\" style=\"display: inline-block;background-color: #a855f7;color: #ffffff;padding: 10px 22px;border-radius: 6px;text-decoration: none;font-weight: bold;font-size: 14px\">Create Free Account<\/a>\n<\/div>\n<h2>Frequently Asked Questions<\/h2>\n<div style=\"border-bottom: 1px solid #e2e8f0;padding: 12px 0\">\n<h4 style=\"margin: 0 0 8px 0;color: #1e293b\">Why is my database username limited to 8 characters in cPanel?<\/h4>\n<p style=\"margin: 0;color: #475569;font-size: 14px\">Older MySQL specifications limited usernames to 16 characters total. Because cPanel prepends your account prefix (up to 8 characters), the customizable portion is restricted to 8 characters to ensure compatibility.<\/p>\n<\/div>\n<h2>Managing Multiple WordPress Databases on a Single Hosting Account<\/h2>\n<p>In cPanel, you can create separate databases for staging subdomains, development branches, and production sites. Assigning unique database users with dedicated passwords to each site ensures that a compromised test environment cannot access production customer records.<\/p>\n<div style=\"border-bottom: 1px solid #e2e8f0;padding: 12px 0\">\n<h4 style=\"margin: 0 0 8px 0;color: #1e293b\">Can a single database user access multiple databases?<\/h4>\n<p style=\"margin: 0;color: #475569;font-size: 14px\">Yes. In cPanel, you can assign the same user to multiple databases by repeating the <em>Add User to Database<\/em> step with full privileges for each database.<\/p>\n<\/div>\n<div style=\"background-color: #f1f5f9;padding: 15px;border-radius: 8px;margin: 20px 0\">\n<h4 style=\"margin-top: 0;color: #1e293b\">Pro Sysadmin Tip: Renaming cPanel Databases Safely<\/h4>\n<p style=\"margin: 0;color: #475569;font-size: 14px\">In modern cPanel versions, you can rename a database in 1-click under MySQL Databases &gt; Modify Databases without exporting and re-importing SQL files. Remember to update <code>DB_NAME<\/code> in your application config immediately after renaming.<\/p>\n<\/div>\n<p>By properly isolating database users and enforcing strict privilege boundaries, you establish an enterprise-grade security standard across all your hosted web applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quick Answer: To create a MySQL database and user in cPanel: 1) Navigate to MySQL Databases (or MySQL Database Wizard), 2) Enter your database name and click Create Database, 3) Create a new MySQL user with a strong password, and 4) Under Add User to Database, select your user and database, check ALL PRIVILEGES, and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1608,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[],"class_list":["post-1609","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1609","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/comments?post=1609"}],"version-history":[{"count":4,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1609\/revisions"}],"predecessor-version":[{"id":1651,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1609\/revisions\/1651"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media\/1608"}],"wp:attachment":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media?parent=1609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/categories?post=1609"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/tags?post=1609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}