I am trying to restore database from .sql file , i have created the database in phpmyadmin and also using the create if not exist command in the .sql file which i am restori
I had the same issue, i run this command on command line and just like you i had added the ';' at the end. Removing it solved the issue. Instead of this
mysql -uroot -pmypassword mydatabase<mydatabase.sql;
try this
mysql -uroot -pmypassword mydatabase<mydatabase.sql
If dump file contains:
CREATE DATABASE mydatabasename;
USE mydatabasename;
You may just use in CLI:
mysql -uroot –pmypassword < mydatabase.sql
It works.
Open the sql file and comment out the line that tries to create the existing database and remove USE mydatabasename
and try again.
Create database which gave error as Unknown database, Login to mysql shell:
sudo mysql -u root -p
create database db_name;
Now try restoring database using .sql file, -p flag will ask for a sql user's password once command is executed.
sudo mysql -u root -p db_name < db_name.sql
Whatever the name of your dump file, it's the content which does matter.
You need to check your mydatabase.sql
and find this line :
USE mydatabasename;
This name does matter, and it's the one you must use in your command :
mysql -uroot -pmypassword mydatabasename<mydatabase.sql;
Two options for you :
USE mydatabasename;
in your dump, and keep using :mysql -uroot -pmypassword mydatabase<mydatabase.sql;
mysql -uroot -pmypassword mydatabasename<mydatabase.sql;
I found these lines in one of the .sql files
"To connect with a manager that does not use port 3306
, you must specify the port number:
$mysqli = new mysqli('127.0.0.0.1','user','password','database','3307');
or, in procedural terms:
$mysqli = mysqli_connect('127.0.0.0.1','user','password','database','3307');"
It resolved the error for me . So i will suggest must use port number while making connection to server to resolve the error 1049
(unknown database).