Skip to content
Advertisement

ERROR 1046:No database selected

I would like to create a SQL database but this error occurs I do not know why. Can somebody help me?

My SQL statement:

CREATE TABLE 'users'(
    'user_id' int (11) NOT NULL AUTO_INCREMENT,
    'username' varchar (255) DEFAULT NULL,
    'password' varchar (255) DEFAULT NULL,
    PRIMARY KEY ('user_id')
)ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 

Can somebody help me?

Advertisement

Answer

Firstly you need to tell MySQL which database you would like to use to create a table:

USE your_database_name;

If your database does not exist yet, you have to create one:

CREATE DATABASE your_database_name;

then tell MySQL that you want to use it:

USE your_database_name;

and then you can create a table.

Hope it will help you to solve this problem 🙂

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement