phpmyadmin import database error

2019-09-24 05:11发布

I try to import a MySQL database on the localhost through phpmyadmin and i receive this error. what it means? and how can i solve it? any ideas?

SQL query:

--
-- Database: `casasdl_mag`
--
--
-- Database: `casasdl`
--
-- --------------------------------------------------------
--
-- Table structure for table `admin_assert`
--
CREATE TABLE IF NOT EXISTS  `admin_assert` (

 `assert_id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT  'Assert ID',
 `assert_type` VARCHAR( 20 ) DEFAULT NULL COMMENT  'Assert Type',
 `assert_data` TEXT COMMENT  'Assert Data',
PRIMARY KEY (  `assert_id` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 COMMENT =  'Admin Assert Table' AUTO_INCREMENT =1;

MySQL said: Documentation

#1046 - No database selected  

6条回答
Fickle 薄情
2楼-- · 2019-09-24 05:15

When you create a table you need to select a database for that table to insert into

USE databaseName;

run this before your script

USE casasdl;
CREATE TABLE IF NOT EXISTS  `admin_assert` (

 `assert_id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT  'Assert ID',
 `assert_type` VARCHAR( 20 ) DEFAULT NULL COMMENT  'Assert Type',
 `assert_data` TEXT COMMENT  'Assert Data',
PRIMARY KEY (  `assert_id` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 COMMENT =  'Admin Assert Table' AUTO_INCREMENT =1;
查看更多
啃猪蹄的小仙女
3楼-- · 2019-09-24 05:20

Like you can read in error, you have to select your database.

Add USE yourDatabase; at the beginning of the code.

查看更多
Deceive 欺骗
4楼-- · 2019-09-24 05:22

The USE db_name statement tells MySQL to use the db_name database as the default (current) database for subsequent statements. The database remains the default until the end of the session or another USE statement is issued.

Refer: http://dev.mysql.com/doc/refman/5.6/en/use.html

查看更多
贼婆χ
5楼-- · 2019-09-24 05:23

if you are using external php, then do not use use database syntax or mysql-select_db("database"); syntax. Instead use mysqli_connect which accept database name.

查看更多
贪生不怕死
6楼-- · 2019-09-24 05:25

mysql or each db backend should import your tables into a Database , so it needs you introduce a db name , indeed you should tell to mysql :

use mydbname;

you can create it from :

mysqladmin -uroot -p create mydbname
mysql -uroot -p mydbname < mysqlfile.sql
查看更多
做自己的国王
7楼-- · 2019-09-24 05:32

Another option is within phpmyadmin Select DB from the left sidebar and inside it import will work.

查看更多
登录 后发表回答