Create DB → Create User → Grant Access → Import via phpMyAdmin → Connect Your App
⭐ For shared hosting & VPS on cPanel. Screens/labels vary slightly by theme. No SSH required.
⚡ Quick‑Start Checklist (At a Glance)
-
✅ Create Database: cPanel → MySQL® Databases → Create New Database
-
✅ Create User: cPanel → MySQL® Databases → MySQL Users → Add New User
-
✅ Grant Privileges: Add User to Database → ALL PRIVILEGES (or least‑privilege)
-
✅ Import: cPanel → phpMyAdmin → select DB → Import → pick
.sql
/.sql.gz
→ Go -
✅ Connect App: host
localhost
, DB name, user, password` → update config/.env
Estimated time: 5–10 minutes ⏱️
Works for: WordPress, Laravel, Magento, custom PHP apps, etc. 🧩
🔎 Why this guide?
Migrating or restoring a website often starts with the database. This step‑by‑step cPanel guide shows you exactly how to create a MySQL database and user, assign privileges, import with phpMyAdmin, and connect your application—all without SSH. Ideal for shared hosting and VPS environments, these instructions help you avoid common errors like Access denied, Unknown collation, and MySQL server has gone away while following security best practices.
Target keywords: import MySQL database in cPanel, phpMyAdmin import, create MySQL user in cPanel, WordPress database restore, cPanel database migration, shared hosting MySQL, VPS MySQL setup.
🧰 Prerequisites
-
📄 A database dump:
.sql
(preferred) or compressed.sql.gz
/.zip
-
🔤 Know the character set/collation used in the dump (e.g.,
utf8mb4
) -
🔐 cPanel login for the target account
💡 Tip: If your dump includes triggers/views, ensure the export included routines.
🏷️ Understand cPanel Prefixes (Important)
Many cPanel servers auto‑prefix names with your cPanel username:
-
Database →
cpuser_appdb
-
User →
cpuser_appuser
Use the full prefixed names in application configs and during imports.
1) 🗄️ Create the Database
-
Log in to cPanel → open MySQL® Databases
-
Under Create New Database, enter a short name (e.g.,
appdb
) → Create Database -
Note the full name shown (e.g.,
cpuser_appdb
) → Go Back
📝 Keep names short; avoid spaces/special characters.
2) 👤 Create a MySQL User
-
In MySQL® Databases, scroll to MySQL Users → Add New User
-
Enter a username (e.g.,
appuser
) and generate a strong password -
Click Create User → Go Back
Best practices
-
🔑 Use a unique user per application
-
🔄 Rotate passwords after staff changes or incidents
3) 🔗 Grant the User Access to the Database
-
In Add User To Database, pick the user and database
-
Click Add
-
On the privileges screen:
-
✅ ALL PRIVILEGES for initial setup/import, or
-
🔒 Least‑privilege (SELECT/INSERT/UPDATE/DELETE; plus CREATE/ALTER/INDEX for migrations)
-
-
Make Changes
🛡️ You can tighten privileges after the import.
4) ⬆️ Import the Database with phpMyAdmin
-
Return to cPanel Home → open phpMyAdmin
-
In the left sidebar, click your database (it will be empty)
-
Click the Import tab
-
Choose File → select your dump (
.sql
or.sql.gz
) -
Confirm Format = SQL; set Character set to
utf8mb4
if applicable -
(Optional) Enable Partial import to help with long uploads
-
Scroll down → Go
📏 File Size Limits & Large Imports (No SSH)
-
🗜️ Compress to
.sql.gz
and retry -
✂️ Split the dump into smaller chunks and import sequentially
-
🧩 If enabled by your host: cPanel → Backup → Restore a MySQL Database
-
🤝 Open a support ticket for server‑side import if the file is very large
⚠️ If you see timeouts (MySQL server has gone away), try
.sql.gz
or ask support to raise limits temporarily.
5) 🔌 Connect Your Application (DB Credentials)
Most apps need four values:
-
DB host: usually
localhost
-
DB name: e.g.,
cpuser_appdb
-
DB user: e.g.,
cpuser_appuser
-
DB password: the strong password you created
PHP (mysqli) connection test
<?php
$host = 'localhost';
$db = 'cpuser_appdb';
$user = 'cpuser_appuser';
$pass = 'REPLACE_WITH_STRONG_PASSWORD';
$con = mysqli_connect($host, $user, $pass, $db);
if (!$con) {
die('Connection failed: ' . mysqli_connect_error());
}
echo 'Connected successfully and database selected!';
mysqli_close($con);
PHP (PDO) connection test
<?php
$dsn = 'mysql:host=localhost;dbname=cpuser_appdb;charset=utf8mb4';
$user = 'cpuser_appuser';
$pass = 'REPLACE_WITH_STRONG_PASSWORD';
try {
$pdo = new PDO($dsn, $user, $pass, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
echo 'Connected with PDO!';
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
Sample .env
(generic PHP app)
DB_HOST=localhost
DB_DATABASE=cpuser_appdb
DB_USERNAME=cpuser_appuser
DB_PASSWORD=REPLACE_WITH_STRONG_PASSWORD
DB_CHARSET=utf8mb4
DB_COLLATION=utf8mb4_unicode_ci
🔁 After updating configs, clear application caches and retest.
6) 🧪 Post‑Import Verification (QA)
-
🔢 Row counts: open key tables in phpMyAdmin; confirm expected counts
-
🔤 Charset & collation: ensure
utf8mb4
/utf8mb4_unicode_ci
where required -
🧷 Routines/Triggers/Views: present and valid
-
🕒 Time zones: check displayed timestamps; align app/server time zone if needed
-
🧭 Functional test: log in to the app, navigate core pages, submit a form
7) 🧯 Common Errors & Fixes
Access denied for user
👉 Wrong DB name/user/password, or user not attached. Re‑attach user and retest.
MySQL server has gone away / timeout
👉 File too large or slow. Use .sql.gz
, split the dump, or request server‑side import.
Unknown collation (e.g., utf8mb4_0900_ai_ci
)
👉 Target MySQL/MariaDB older than source. Re‑export with common collation (e.g., utf8mb4_general_ci
) or replace collation strings in the dump, then import.
Foreign key constraint errors
👉 Creation order conflicts. Wrap dump with:
SET FOREIGN_KEY_CHECKS=0;
-- your schema + data here
SET FOREIGN_KEY_CHECKS=1;
Duplicate entry for key
👉 Target has existing data. Drop conflicting tables first, or import into a fresh DB.
#1044 – Access denied to database
👉 Insufficient privileges. Temporarily grant ALL PRIVILEGES, import, then tighten.
8) 🔒 Security & Maintenance Best Practices
-
🧑💻 Unique DB user per app; never reuse across projects
-
🪪 Least privilege in production (remove CREATE/ALTER if not needed)
-
🧰 Keep dumps clean (no test admin users or debug data)
-
🧾 Store credentials securely; rotate after staff changes
-
💽 Schedule backups before major updates/migrations
🙋 FAQ
Q1: Where do I find phpMyAdmin in cPanel?
A: From cPanel Home, open phpMyAdmin under the Databases section.
Q2: What is my MySQL host?
A: Usually localhost
in cPanel environments. If remote DB is enabled, your host may differ.
Q3: Can I import a .sql.zip
file?
A: Prefer .sql
or .sql.gz
. Some phpMyAdmin builds accept .zip
, but .gz
is more reliable.
Q4: My file is bigger than the upload limit. What now?
A: Compress to .sql.gz
, split into parts, or ask hosting support for a server‑side import.
Q5: I see Access denied
after import—what changed?
A: Ensure the user is attached to the database and the prefix matches (cpuser_…
).
🤝 Need Help from Domain India?
-
📚 Knowledgebase: https://www.domainindia.com/knowledgebase
-
🎫 Submit a Ticket: https://www.domainindia.com/support
Attach your dump file and specify the target DB name, user, and expected charset/collation.
Learn how to import a MySQL database in cPanel step‑by‑step: create database and user, assign privileges, import with phpMyAdmin, and connect your app. Perfect for shared hosting & VPS.
cPanel MySQL import, phpMyAdmin import, create MySQL user cPanel, WordPress database restore, shared hosting MySQL, VPS MySQL database setup, database migration cPanel.
🔧 Appendix: Formats & Options
-
.sql
– raw SQL; most portable -
.sql.gz
– compressed; best for large imports via phpMyAdmin -
Partial import – helps resume long uploads
-
Definer fixes – replace
DEFINER=\
olduser`@`%`with
CURRENT_USER` in views/triggers if needed
✅ Summary
You’ve created a database and user in cPanel, granted privileges, imported your .sql
with phpMyAdmin, and connected your app using the correct prefixed credentials. Follow the QA checks and best practices above for a stable, secure deployment.