phpMyAdmin“未选择数据库”MySQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13950853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
phpMyAdmin "No database selected" MySQL
提问by NateHunt
I downloaded a MySQL backup file and promptly imported into MAMP's phpMyAdmin. I got this return:
我下载了一个 MySQL 备份文件并立即导入到 MAMP 的 phpMyAdmin。我得到了这个回报:
Error
SQL query:
--
-- Database: `mysql`
--
-- --------------------------------------------------------
--
-- Table structure for table `columns_priv`
--
CREATE TABLE IF NOT EXISTS `columns_priv` (
`Host` CHAR( 60 ) COLLATE utf8_bin NOT NULL DEFAULT '',
`Db` CHAR( 64 ) COLLATE utf8_bin NOT NULL DEFAULT '',
`User` CHAR( 16 ) COLLATE utf8_bin NOT NULL DEFAULT '',
`Table_name` CHAR( 64 ) COLLATE utf8_bin NOT NULL DEFAULT '',
`Column_name` CHAR( 64 ) COLLATE utf8_bin NOT NULL DEFAULT '',
`Timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
`Column_priv` SET( 'Select', 'Insert', 'Update', 'References' ) CHARACTER SET utf8 NOT NULL DEFAULT '',
PRIMARY KEY ( `Host` , `Db` , `User` , `Table_name` , `Column_name` )
) ENGINE = MYISAM DEFAULT CHARSET = utf8 COLLATE = utf8_bin COMMENT = 'Column privileges';
MySQL said:
#1046 - No database selected
I did not alter the .sql file at all. Any hints on how i can get this puppy going locally?
我根本没有更改 .sql 文件。关于如何让这只小狗在本地生活的任何提示?
Thanks!
谢谢!
回答by Anwar
Just create a database with some name first of all. Click on that database and then import your table. The problem here is when you import any table it looks for which database you are using. So, either do as I said above or add this just above CREATE TABLE IF NOT EXISTS columns_priv
(
只需首先创建一个具有某个名称的数据库。单击该数据库,然后导入您的表。这里的问题是当您导入任何表时,它会查找您正在使用的数据库。所以,要么按照我上面说的做,要么在 CREATE TABLE IF NOT EXISTS columns_priv
(
USE your_db_name;//here your_db_name is the database you just created.
That's it.
就是这样。
回答by Jordi Kroon
In phpMyAdmin make a new database or select a existed database. Then import the SQL file.
在 phpMyAdmin 中创建一个新数据库或选择一个现有的数据库。然后导入 SQL 文件。
回答by Dhinakar
Normally Exported sql Script does not have create database syntax. So you should create a database and use manually
通常导出的 sql 脚本没有创建数据库语法。所以你应该创建一个数据库并手动使用
or
或者
Include below lines into your first line of the sql script.
将以下行包含在 sql 脚本的第一行中。
create database database_name;
use database_name;
Note : If database already exists then you only include second statement.
注意:如果数据库已经存在,那么你只包含第二个语句。
Now you can import without Error.
现在您可以毫无错误地导入。
回答by Dhinakar
You need to create and/or select the database on your sandbox machine before importing the SQL for the table structure and data.
在为表结构和数据导入 SQL 之前,您需要在沙箱机器上创建和/或选择数据库。
In phpMyAdmin, this means choosing a database from the sidebar and then using its import tab. If the database you want to fill doesn't exist, you have to create it first using the Create new database form.
在 phpMyAdmin 中,这意味着从侧边栏中选择一个数据库,然后使用其导入选项卡。如果要填充的数据库不存在,则必须首先使用“创建新数据库”表单创建它。
After import, you should confirm that the export-import process hasn't affected the anonymous user record (uid 0).
导入后,您应该确认导出导入过程没有影响匿名用户记录(uid 0)。
Credits to @scronide
归功于@scronide
回答by Albert.Qing
If the DB is exported from sql with phpmyadmin, you should use custom method. And chose
如果数据库是使用 phpmyadmin 从 sql 导出的,则应使用自定义方法。并选择了
include a timestamp of when databases were created,last updated,and last checked
包括数据库创建、上次更新和上次检查的时间戳
this sql will contains
这个 sql 将包含
create database database_name; use database_name;
创建数据库database_name; 使用数据库名称;
回答by Robot Boy
Create the database and in the sql file that you are importing add this
USE db_name;
创建数据库并在您要导入的 sql 文件中添加此
USE db_name;
回答by Awais
you just have to use USE db_name;
at the starting of Sql code file which you exported and the problem will be resolved
你只需要USE db_name;
在你导出的Sql代码文件的开头使用,问题就会解决