Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Error 1046 No database Selected, how to resolve?

Error SQL query:

--
-- Database: `work`
--
-- --------------------------------------------------------
--
-- Table structure for table `administrators`
--
CREATE TABLE IF NOT EXISTS `administrators` (

`user_id` varchar( 30 ) NOT NULL ,
`password` varchar( 30 ) NOT NULL ) ENGINE = InnoDB DEFAULT CHARSET = latin1;


MySQL said:
#1046 - No database selected

need some help here.
by

2 Answers

aashaykumar
You need to tell MySQL which database to use:

USE database_name;

before you create a table.

In case the database does not exist, you need to create it as:

CREATE DATABASE database_name;

followed by:

USE database_name;
RoliMishra
You can also tell MySQL what database to use (if you have it created already):

mysql -u example_user -p --database=example < ./example.sql

Login / Signup to Answer the Question.