---
title: "Database import fails: CREATE DATABASE line"
date: "2015-05-20"
category: "mysql"
slug: "database-import-fails-create-database-line"
---

Restoring a database backup via the control panel, mysql CLI, or phpMyAdmin may fail with an error like:

#1044 - Access denied for user 'myuser'@'localhost' to database 'mynewdb'

## Cause

The backup file contains a `CREATE DATABASE` statement that fails because database creation requires elevated permissions. All databases must be created through the [[creating-database]] interface to ensure proper account namespacing.

## Solution

### Step 1: Create the Database

Create the destination database within the control panel before importing.

### Step 2: Remove Conflicting Lines

Remove the `CREATE DATABASE` and `USE` lines from the SQL file. These typically appear together:

CREATE DATABASE IF NOT EXISTS \`mynewdb\` /\*!40100 DEFAULT CHARACTER SET utf8mb4 \*/; USE \`mynewdb\`

Delete both lines so they are empty.

### Step 3: Import

**phpMyAdmin:** Select the target database in the left panel, then choose _Import_ from the tabs.

**Terminal:** Specify the database name in the command when importing from the [[accessing-terminal]]:

```
mysql -u username -ppassword mynewdb < dbbackup.sql
```
