Configure MySQL databases, users, permissions, and script connections.
Lesson 3.1: Creating MySQL Databases, Users & Privileges
- cPanel database prefixes
- User password generation
- User-to-database privilege mapping
In shared cPanel hosting, database administration is restricted: you cannot create databases directly within phpMyAdmin. Instead, navigate to cPanel > Databases > 'Manage My Databases'.
Create a new database. cPanel will prepend your account username and an underscore (e.g., oyudo_sms). Next, navigate to the 'Add New User' section. Enter a username and utilize the Password Generator to generate a strong credential. Record the database name, username, and password in a secure scratchpad. Finally, locate 'Add User To Database', select the user and database you created, click Add, check 'ALL PRIVILEGES', and commit the change.
Practical work
- Create a database and database user through cPanel Manage My Databases.
- Assign the user to the database and grant ALL PRIVILEGES.
- Record the full prefixed database name, username, and password.
Lesson 3.2: Synchronizing db.php and Troubleshooting SQL Error 1044
- Editing db.php in File Manager
- Diagnosing Error 1044
- Sanitizing SQL dumps in VS Code
- Import validation
In File Manager, edit your database connection file (db.php). Maintain $host as 'localhost', and update $username, $password, and $database to match your live cPanel credentials. Save the file.
Next, open cPanel phpMyAdmin, select your live database, and navigate to the Import tab. If your SQL dump contains an explicit 'CREATE DATABASE' or 'USE' query, the import will fail with Error #1044 (Access denied). To resolve this, open your .sql file in a code editor like VS Code, locate and delete the CREATE DATABASE and USE statements, save, and re-import via phpMyAdmin. Finally, test both member and administrative logins on your live subdomain to confirm the application is fully operational.
Practical work
- Edit db.php using cPanel File Manager and enter the live credentials.
- Open the local .sql file, remove any CREATE DATABASE and USE queries, and save.
- Import the modified .sql file into the live database via cPanel phpMyAdmin and test site logins.