phpMyAdmin "No database selected" MySQL - mysql

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!

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.

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

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.

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

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

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;

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

Related

Importing database into WAMP Server

I have a project sent to me by a friend and i am having serious issues importing the database into my WAMP Server. I end up getting Mysql error
Error
SQL query:
--
-- Database: `drivers_endorsements`
--
-- --------------------------------------------------------
--
-- Table structure for table `admin`
--
CREATE TABLE IF NOT EXISTS `admin` (
`admin_id` int(11) NOT NULL,
`username` varchar(30) NOT NULL,
`password` varchar(12) NOT NULL,
`name` varchar(40) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3
MySQL said: Documentation
#1046 - No database selected
Firstly you have to create database manually or select the existing one in phpmyadmin (as mentioned WAMP server is used ) and then import the .sql file in it, and the database name should be same as that of used in application else will not work with desired application to which the database is linked.
It's not really a big deal! The message itself is self-explanatory. You need to select an existing database first & then try your import.
Or you could possibly add the following at the very top of your DB script that you trying to import -
CREATE DATABASE IF NOT EXISTS drivers_endorsements;
USE drivers_endorsements;

No database selected when import the script

I created a script using MySqlWorkbench, at the top of the script there is this:
CREATE SCHEMA IF NOT EXISTS `contacts` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
USE `contacts` ;
when I import this script in PhpMyAdmin, I get:
SQL query:
CREATE TABLE `contact` (
`id` int(11) NOT NULL,
`name` varchar(45) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
MySQL said: Documentation
1046 - No database selected
Why the schema contacts isn't creating a new database?
Use CREATE TABLE contacts.contact
(not allowed to comment yet, so forced to use answer.)

Importing a MySQL database

Trying to import a MySQL database using PHP-Admin. When I try to import the file backed-up by my host, I get this error message:
SQL query:
DROP TABLE IF EXISTS `wp_commentmeta`
MySQL said: Documentation
#1046 - No database selected
I have also tried to export the database myself, then trying to import that specific file. When I do that, however, I get a completely different error message:
SQL query:
CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
`meta_id` bigint(20) unsigned NOT NULL,
`comment_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`meta_key` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`meta_value` longtext COLLATE utf8mb4_unicode_ci
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
MySQL said: Documentation
#1046 - No database selected
What can I do to resolve this?
You need to USE a database. You could edit your file and add the line at the top, something like:
USE databasename;
Some tools will let you set a default database when restoring from backup. If you haven't selected one that could be a problem.
If you haven't created a database you'll need to do that first.
You need to select which database you are importing to in your SQL. Your first statement should be:
USE DATABASE `db_name`;
You have no database selected.
Find which databases exist
SHOW DATABASES:
and then select one for use
USE `database_name`
You say that you are importing into a new host, so I would assume that you do not already have a database created;
CREATE DATABASE `database_name`
Now you can USE that database you just created; and your queries should now work.

phpmyadmin import database error

I try to import a MySQL database on the localhost through phpmyadmin and i receive this error. what it means? and how can i solve it? any ideas?
SQL query:
--
-- Database: `casasdl_mag`
--
--
-- Database: `casasdl`
--
-- --------------------------------------------------------
--
-- Table structure for table `admin_assert`
--
CREATE TABLE IF NOT EXISTS `admin_assert` (
`assert_id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Assert ID',
`assert_type` VARCHAR( 20 ) DEFAULT NULL COMMENT 'Assert Type',
`assert_data` TEXT COMMENT 'Assert Data',
PRIMARY KEY ( `assert_id` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 COMMENT = 'Admin Assert Table' AUTO_INCREMENT =1;
MySQL said: Documentation
#1046 - No database selected
When you create a table you need to select a database for that table to insert into
USE databaseName;
run this before your script
USE casasdl;
CREATE TABLE IF NOT EXISTS `admin_assert` (
`assert_id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Assert ID',
`assert_type` VARCHAR( 20 ) DEFAULT NULL COMMENT 'Assert Type',
`assert_data` TEXT COMMENT 'Assert Data',
PRIMARY KEY ( `assert_id` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 COMMENT = 'Admin Assert Table' AUTO_INCREMENT =1;
Like you can read in error, you have to select your database.
Add USE yourDatabase; at the beginning of the code.
mysql or each db backend should import your tables into a Database , so it needs you introduce a db name , indeed you should tell to mysql :
use mydbname;
you can create it from :
mysqladmin -uroot -p create mydbname
mysql -uroot -p mydbname < mysqlfile.sql
if you are using external php, then do not use use database syntax or mysql-select_db("database"); syntax. Instead use mysqli_connect which accept database name.
The USE db_name statement tells MySQL to use the db_name database as the default (current) database for subsequent statements. The database remains the default until the end of the session or another USE statement is issued.
Refer: http://dev.mysql.com/doc/refman/5.6/en/use.html
Another option is within phpmyadmin Select DB from the left sidebar and inside it import will work.

Error #1046 - No database selected SQL import on XAMPP

I am trying to import the SQL database from my Drupal production site into a sandbox testing site on my local machine. I currently use XAMPP on my machine here at work.
I have downloaded my db aipiadxxm_if9DHdr.sql and then I go to the phpMyAdmin on http://localhost/phpmyadmin/index.php then to -> Import.
After I import the db I get this Error:
SQL query:
--
-- Database: `aipiadxxm_if9DHdr.sql`
--
-- --------------------------------------------------------
--
-- Table structure for table `if9d_access`
--
CREATE TABLE IF NOT EXISTS `if9d_access` (
`aid` int( 11 ) NOT NULL AUTO_INCREMENT ,
`mask` varchar( 255 ) NOT NULL default '',
`type` varchar( 255 ) NOT NULL default '',
`status` tinyint( 4 ) NOT NULL default '0',
PRIMARY KEY ( `aid` )
) ENGINE = MYISAM DEFAULT CHARSET = utf8 AUTO_INCREMENT =1;
MySQL said: Documentation
#1046 - No database selected
What is causing this error message: #1046 - No database selected ?
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).