错误 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

这里需要帮助。


当前回答

当我试图导入以前创建的数据库时,我遇到了同样的错误。以下是我解决这个问题的方法:

创建新的数据库

2—使用Use命令

3-再试一次

这对我很有用。

其他回答

如果你通过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.

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

注意使用空密码

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

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

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

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

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

引用伊万的话: 如果导入数据库,需要先创建一个同名的数据库,然后选择它,然后将现有的数据库导入到它。 希望它对你有用!”

以下是步骤: 创建一个数据库,例如my_db1, utf8_general_ci。 然后单击进入该数据库。 然后点击“导入”,选择数据库:my_db1.sql

应该就这些了。

在mysql中新建一个数据库。选择新的DB。(如果你现在使用mysql phpmyadmin在顶部,它会像'服务器:…* >>数据库)。现在进入导入选项卡选择文件。导入!

举例解决方案

错误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;