phpMyAdmin “No database selected” MySQL

2019-01-23 07:02发布

问题:

I downloaded a MySQL backup file and promptly imported into MAMP's phpMyAdmin. I got this return:

Error
SQL query: 

--
-- Database: `mysql`
--
-- --------------------------------------------------------
--
-- Table structure for table `columns_priv`
--
CREATE TABLE IF NOT EXISTS  `columns_priv` (

 `Host` CHAR( 60 ) COLLATE utf8_bin NOT NULL DEFAULT  '', 
 `Db` CHAR( 64 ) COLLATE utf8_bin NOT NULL DEFAULT  '',
 `User` CHAR( 16 ) COLLATE utf8_bin NOT NULL DEFAULT  '',
 `Table_name` CHAR( 64 ) COLLATE utf8_bin NOT NULL DEFAULT  '',
 `Column_name` CHAR( 64 ) COLLATE utf8_bin NOT NULL DEFAULT  '',
 `Timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
 `Column_priv` SET(  'Select',  'Insert',  'Update',  'References' ) CHARACTER SET utf8          NOT NULL DEFAULT  '',
PRIMARY KEY (  `Host` ,  `Db` ,  `User` ,  `Table_name` ,  `Column_name` )
) ENGINE = MYISAM DEFAULT CHARSET = utf8 COLLATE = utf8_bin COMMENT =  'Column      privileges';

MySQL said: 

#1046 - No database selected 

I did not alter the .sql file at all. Any hints on how i can get this puppy going locally?

Thanks!

回答1:

Just create a database with some name first of all. Click on that database and then import your table. The problem here is when you import any table it looks for which database you are using. So, either do as I said above or add this just above CREATE TABLE IF NOT EXISTS columns_priv (

USE your_db_name;//here your_db_name is the database you just created. 

That's it.



回答2:

In phpMyAdmin make a new database or select a existed database. Then import the SQL file.



回答3:

Normally Exported sql Script does not have create database syntax. So you should create a database and use manually

or

Include below lines into your first line of the sql script.

create database database_name;
use database_name;

Note : If database already exists then you only include second statement.

Now you can import without Error.



回答4:

You need to create and/or select the database on your sandbox machine before importing the SQL for the table structure and data.

In phpMyAdmin, this means choosing a database from the sidebar and then using its import tab. If the database you want to fill doesn't exist, you have to create it first using the Create new database form.

After import, you should confirm that the export-import process hasn't affected the anonymous user record (uid 0).

Credits to @scronide



回答5:

If the DB is exported from sql with phpmyadmin, you should use custom method. And chose

include a timestamp of when databases were created,last updated,and last checked

this sql will contains

create database database_name; use database_name;



回答6:

Create the database and in the sql file that you are importing add this USE db_name;



回答7:

you just have to use USE db_name; at the starting of Sql code file which you exported and the problem will be resolved