简体   繁体   中英

Importing single MySQL .sql file for ENTIRE Database | No Database Selected Error

I know it's probably not the correct way to do it, but I exported my entire database to a file called localhost.sql. I don't know how to import this to my new database, because it asks for a target database to put it in, but I don't have one, I need it to import the entire database, not to a table. Or at least that's how I understand it.

When I go to PhpMyAdmin and go to import and choose that file, then click Go, it gives this error...

Error:

SQL query CREATE TABLE IF NOT EXISTS pinnums ( pin varchar(5) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1

1046 - No database selected

Yes it's pretty self-explanitory, but hours of looking at forums and trying stuff that dosn't make sence/work...I don't know...

I don't think I can show my database file as it contains sensitive info.

Most of my website runs off of these databases that I can't access, so I need them or all of my work is done for. :( Any thoughts help!

You need to first create a new database in the target database server and then import the .sql file to that database.

`#mysql> create database <newdatabasename>;`
#shell> mysql -u<user> -p  <newdatabasename>  < localhost.sql

Yay! I had a small hypothesis that the .sql file was text-editor-readable, and I was right, so I manually recreated all of my databases and filled them using the pre-made code in the .sql backup file. The reason for the error, is because which database the info should go in wasn't commented out for some reason.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM