Import Full MySQL Dump - mysql

I have exported a full backup of a database with HeidiSQL 7.
Now when importing it via PHPMyAdmin, I noticed that I MUST select the database information_schema, because that's how the DB is exported (Or this is how HeidiSQL 7 exports databases as objects to an SQL file?).
However, that is a problem because when I import (the exported file) with HeidiSQL 7 (instead of PHPMyAdmin), while selecting the information_schema database, and clicking on Import SQL file (from the tools menu), it says that access is denied for the root user.
In PHPMyAdmin, the option to import is not available when selecting the database information_schema.
How do I import my full database dump? (This is how I exported it: HeidiSQL > export database objects to SQL file)
Edit:
I tried it with the command line, but without luck:
C:\Programs\XAMPP\mysql\bin>mysql --verbose --user=root Information_schema < DT.
sql
--------------
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */
--------------
--------------
/*!40101 SET NAMES utf8 */
--------------
--------------
/*!40014 SET FOREIGN_KEY_CHECKS=0 */
--------------
--------------
/*!40000 ALTER TABLE `CHARACTER_SETS` DISABLE KEYS */
--------------
ERROR 1044 (42000) at line 13: Access denied for user 'root'#'localhost' to data
base 'information_schema'
C:\Programs\XAMPP\mysql\bin>
This is a snippet of the SQL file:
http://pastebin.com/6hwhK2CJ
Note: The password for my root user is blank.
Maybe another solution for my problem:
How do I import only the database I want, from the SQL file? For example a database with the name "Employees"? Because that SQL file should contain a few databases.
Edit2:
(answer to first comment)
I downloaded MySQL Workbench, setup the connection...
03:23:08 Restoring C:\Files\DB.sql
Running: mysql.exe --defaults-extra-file="c:\files\temp\tmplnjwd6.cnf" --host=localhost --user=root --port=3306 --default-character-set=utf8 --comments < "C:\\Files\\DB.sql"
ERROR 1046 (3D000) at line 13: No database selected
Operation failed with exitcode 1
03:23:08 Import of C:\Files\DB.sql has finished with 1 errors

INFORMATION_SCHEMA is a pseudo, read-only database (in fact, it is an "ANSI standard set of read-only views").
You need to remove all dump data related to this pseudo database, as there is absolutely no way to import it.
Notepad++ is able to easily handle a 9 MB file, and also provides nice syntax highlighting.

Related

Import/Restore MySQL database?

I have 2 different dumps from a prev setup(MySQL 5.xx). The first one is a self-contained file on about 250 MB, the other is a folder with 317 SQL files. Both is dumps from the same setup, just in different formats.
Now I need to restore one of them in the new MySQL 8 setup.
The folder dump contains a total of 10 schemas including sys. The MySQL 8 is just created so there is only a sys schema.
When I run the Import I just get a lot of errors like this:
10:09:24 Restoring myvideos93 (streamdetails) Running: mysql.exe
--defaults-file="c:\users\jimmy\appdata\local\temp\tmpk7oihn.cnf" --protocol=tcp --host=localhost --user=root --port=3306 --default-character-set=utf8 --comments --database=myvideos93 < "F:\20180605
Backup\Documents\dumps\Dump20180605\myvideos93_streamdetails.sql"
ERROR 1049 (42000): Unknown database 'myvideos93'
Operation failed with exitcode 1
I'm doing this from MySQL Workbench on Windows 10 x64.
How to solve it?
Okay, so I hade to create each schema manually, but that was not enouth. I also hade to run the import 3 times until I only got 1 minor error. MySQL Windows components are still surprisingly unstable.

ERROR 1049 (42000): Unknown database, localized Wordpress database

I'm moving my wordpress website to local for testing purpose.
I encountered the error below when I'm trying to import the .sql that I export from CPanel PHPMyadmin into local MYSQL Workbench.
FYI, I'm using MYSQL Workbench 6.0 and MYSQL Administrator 1.2.17
15:08:07 Restoring C:\Users\abc\Desktop\db.sql
Running: mysql.exe --defaults-extra-file="c:\users\abc\appdata\local\temp\3\tmpdemide.cnf" --host=localhost --user=root --port=3307 --default-character-set=utf8 --comments --database=db < "C:\\Users\\abc\\Desktop\\db.sql"
ERROR 1049 (42000): Unknown database 'db'
Operation failed with exitcode 1
15:08:08 Import of C:\Users\abc\Desktop\db.sql has finished with 1 errors
Apparently the export was done without specifying a database (schema), so you have to create it manually first before you can import the dump. MySQL Workbench allows to import a dump to a different (including a new) schema. You can specify this on the import page:
You looks like you have to create a database first
CREATE DATABASE db;
and then import your sql file.

Restore database in mysql command line

I have taken a backup of a database from one server and trying to restore it in another server.
Mysql version is 5.5
When I try to restore the database using the following command, screen -r
mysql -u root -p password mydb < mydump.sql
ERROR 1005 (HY000) at line 356: Can't create table 'mydb.mytable' (errno: 150)
I understand this is foreignkey constraint problem. The dump file has the following statement inside.
/*!40014 SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
But it is still failing. My dumo file is very large is size, so opening it and editing is not possible. So instead of adding SET FOREIGN_KEY_CHECKS=0; in the dump, can I directly set it inside the mysql commandline like the following?
mysql> SET FOREIGN_KEY_CHECKS=0;
...
mysql> source "mydump.sql";
...
mysql> SET FOREIGN_KEY_CHECKS=1;
Will it work? My database reload takes hours to complete. So I am asking the help here before spending hours on this.
Thanks for the help.
Usually, I'll just pipe in 2 sql files -- first, a one-liner with SET FOREIGN_KEY_CHECKS=0;, and then dump file. You needn't worry about setting it back; it will only last for the current session (which will terminate when the files have been loaded).
FYI, you can also use sed -i 1i"SET FOREIGN_KEY_CHECKS=0;" dump.sql if you want to permanently prepend this line without visually editing the file.

Cannot import database using PhpMyAdmin with Cpanel on a VPS?

I have a recently set up VPS with cPanel.
I've made a user and created a database, and now I would like to import a database onto it.
However, when I try I get the error message
#1044 - Access denied for user 'user'#'localhost' to database 'database'
I suspect that this can be fixed with WHM, but I do not feel like trial and error just yet.
How would I go about fixing this?
When you import a database using phpMyAdmin, normally you do so by importing a text file with a .sql extension. Here is a section of code that may be in a .sql database backup. In your example, the database you are trying to import is named database.
-- phpMyAdmin SQL Dump
-- version 2.11.9.5
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Apr 02, 2010 at 08:01 AM
-- Server version: 5.0.81
-- PHP Version: 5.2.6
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
CREATE DATABASE database;
-- --------------------------------------------------------
--
-- Table structure for table `table`
--
CREATE TABLE IF NOT EXISTS `table` (
`column1` text NOT NULL,
`column2` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
When using phpMyAdmin to attempt to import such a file, you will receive an error message similar to:
Error
SQL query:
CREATE DATABASE database;
MySQL said: Documentation
#1044 - Access denied for user 'user'#'localhost' to database 'database'
In this scenario, the cPanel username is user. Because of cPanel's database naming conventions, all database names must begin with the cPanel username followed by _. Using this format you can only creat a database named user_database.
The reason this import failed is because of the following line in the .sql file...
CREATE DATABASE database;
Again, you cannot create a database named database, however you can create a database named user_database.
If you change the line that says: CREATE DATABASE so that it creates: user_database instead of database it will again fail with the following message:
Error
SQL query:
CREATE DATABASE user_database;
MySQL said: Documentation
#1044 - Access denied for user 'user'#'localhost' to database 'user_database'
When using cPanel, databases must be created within the cPanel itself.
Here are the steps to correct thi sissue:
Create the user_database database within cPanel
Comment out the CREATE DATABASE command in my .sql file
To do this, simply change:
CREATE DATABASE database;
to
-- CREATE DATABASE database;
You are simply adding dash-dash-space to the front of the line to comment it out so that it will not be executed.
Log into phpMyAdmin, access the user_database database, and then import as normal.
Before dumping your database, grant full access to your new database user created in Cpanel by the same password of that user:
grant all on database_name.* to database_user#localhost identified by 'password';
Then you need to modify your .sql file (can use notepad++), comment out the part where says create and use the new database:
-- Database: dbname
--
-- CREATE DATABASE IF NOT EXISTS dbname DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
-- USE dbname;
then you should be able to import it to your Cpanel.
To make it official...
The file you're attempting to import probably has something that you don't have permissions for. I would check permissions, then the file you're importing.

Importing using MySQL WorkBench... error ERROR 1046 (3D000)

Scenario: building a RoR enviroment locally for development. Production is on EngineYard / GitHub. All now working ok, except DB isn't importing.
I have a .sql file that i've taken from my prod EY site. Now i need to import it to my MySQL locally. I'm using Workbench (as i'm new to this), but getting error below.
Please help?
08:07:43 Restoring /home/james/Downloads/Futology.sql Running: mysql
--defaults-extra-file="/tmp/tmpAVeE58/extraparams.cnf" --host=localhost --user=root --port=3306 --default-character-set=utf8 --comments < "/home/james/Downloads/Futology.sql" ERROR 1046 (3D000) at line 22: No database selected
Operation failed with exitcode 1 08:07:43 Import of
/home/james/Downloads/Futology.sql has finished with 1 errors
Workbench doesn't know the database (schema) you want to use.
In workbench, when using Data Import/Restore, just below where you choose the file to import, it asks "Default Schema to be Imported To"
Just choose the database (schema) you want it to use from the dropdown titled Default Target Schema. If you don't have a database (schema) already, you can create it with the "New" button.
This is confusing because MySQL generally seems to use the term database but Workbench uses schema. They mean the same thing for most purposes. MySQL 'create schema' and 'create database' - Is there any difference
Not used Workbench too much however it's easy enough to do from command line have a look at this (below phpMyAdmin instructions)
The command you're after is:
mysql -u #username# -p #database# < #dump_file#
Simply by choosing your target schema
As I circled in above image
Similar to brynn's answer, simply modify your SQL file and insert the following line at the very top:
use yourdatabasename
Replacing yourdatabasename with the database into which you are trying to import. Also, this database should already be created (albeit empty) before you import into it.
Here's another option that worked for me. I'm using MySQL 5.5 on a VM I set up for importing a large MySQL .sql dump that contained: 1). a create table statement 2). insert statements for inserting a large amount of data into the table.
at the MySQL command line client prompt type:
use yourdatabasename
source d:\yourpath\yourfilename.sql
for more info on the 'source' and other commands, enter ? at the prompt.
The above command line is correct. I found I have to do this when importing .sql files from older versions of MySQL. I also found I had to edit the .sql file (top of the file) and set the db name to be the same as the blank db you create before doing the import.