错误 SQL查询:

--
-- 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说:

#1046 - No database selected

这里需要帮助。


当前回答

注意使用空密码

mysqldump [options] -p '' --databases database_name

将要求密码和抱怨mysqldump:得到错误:1046:“没有数据库选择”时,选择数据库

问题是-p选项要求-p和密码之间没有空格。

mysqldump [options] -p'' --databases database_name

解决了问题(不再需要引号)。

其他回答

MySQL Workbench

通过鼠标右键单击从模式选项卡选择数据库。 将数据库设置为默认模式

注意使用空密码

mysqldump [options] -p '' --databases database_name

将要求密码和抱怨mysqldump:得到错误:1046:“没有数据库选择”时,选择数据库

问题是-p选项要求-p和密码之间没有空格。

mysqldump [options] -p'' --databases database_name

解决了问题(不再需要引号)。

你需要告诉MySQL使用哪个数据库:

USE database_name;

在创建表之前。

如果数据库不存在,您需要将其创建为:

CREATE DATABASE database_name;

紧随其后的是:

USE database_name;

举例解决方案

错误1046发生时,我们错过连接我们的表与数据库。在本例中,我们没有任何数据库,这就是为什么首先我们将创建一个新数据库,然后将指示将该数据库用于创建的表。

# At first you have to create Database 
CREATE DATABASE student_sql;

# Next, specify the database to use
USE student_sql;

# Demo: create a table 
CREATE TABLE student_table(
    student_id INT PRIMARY KEY,
    name VARCHAR(20),
    major VARCHAR(20)
);

# Describe the table 
describe student_table;

如果你通过phpMyAdmin这样做:

I'm assuming you already Created a new MySQL Database on Live Site (by live site I mean the company your hosting with (in my case Bluehost)). Go to phpMyAdmin on live site - log in to the database you just created. Now IMPORTANT! Before clicking the "import" option on the top bar, select your database on the left side of the page (grey bar, on the top has PHP Myadmin written, below it two options:information_schema and name of database you just logged into. once you click the database you just created/logged into it will show you that database and then click the import option.

这招对我很管用。希望能有所帮助