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

这里需要帮助。


当前回答

举例解决方案

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

其他回答

为了增加安全性,当在同一个脚本中使用多个DB时,您可以在查询中指定DB。创建表my_awesome_db.really_cool_table…

如果导入数据库,则需要先创建同名的数据库,然后选择该数据库,然后将现有数据库导入其中。

希望它对你有用!

举例解决方案

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

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

只是想补充:如果你在一个活跃的网站上创建一个mySQL数据库,然后进入PHPMyAdmin和数据库不显示-注销cPanel,然后登录回来,打开PHPMyAdmin,它现在应该在那里。