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

这里需要帮助。


当前回答

为了增加安全性,当在同一个脚本中使用多个DB时,您可以在查询中指定DB。创建表my_awesome_db.really_cool_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.

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

首先选择数据库:使用db_name

然后创建表:CREATE table tb_name ( id int, 名字varchar (255), 工资int, 城市varchar (255) );

这是mysql 5.5版本语法

MySQL Workbench

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

你也可以告诉MySQL使用什么数据库(如果你已经创建了):

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

使用记事本或notepad++编辑SQL文件 增加如下2行:

创建数据库名称; 使用的名字;