mysql 5.7.19 dumping data does not work(input) - mysql

I am trying input datadump to mysql.5.7.19.
I command like below :
mysql -uroot -p temp < temp201708.sql
my my.cnf prints error to /var/log/mysqld.log, but I do not see any error log while dumping.
However, when jobs done, I can not find any tables or data in temp schema. I think I saw some articles that different mysql versions could be a problem. Is it right?
Currently, I do not know what point is wrong, since there were no error log. What should I look for to solve this problem?
Thanks.
FYI, I do not know what version of mysql which made that dump file, I just received from the client.

mysqldump -u root -p DatabaseName > /Path-To-put-The-File/fileName.sql

When doing a dump in mysql:
run cmd
locate location of your mysql server like
Enter:
cd C:\Program Files\MySQL\MySQL Server 5.6\bin
mysqldump -uUsernameHere -pYourPasswordHere dbnamehere > "D:\sample.sql" make sure you have a drive D: in your computer or you can change it.
This is working and tested.
You can use it by calling a .bat file to execute the command.
Otherwise if you want to store a data into your Database use mysql only and not mysqldump and change > to <
like this:
mysql -uUsernameHere -pYourPasswordHere dbnamehere < "D:\sample.sql"

Thanks for answers.
I found the cause.
In the dump file, there are some states like USE mysql;, USE temp;.
So even though I indicate which schema to put in in command line,
it just ignore the command line and follow the script.
I found all of my data in mysql schema.
==========================
Conclusion
if you dump with some command like below
$ > mysqldump -u[user] -p[passwd] [scheme] > dump.sql
it is ok with
$ > mysql -u[user] -p[passwd] [target_scheme] < dump.sql
If not, you should check the contents of .sql file.

Related

Errror 3554 while importing a .sql file

ERROR 3554 (HY000) at line 318: Access to system table 'mysql.innodb_index_stats' is rejected.
Operation failed with exitcode 1
11:27:20 Import of C:\Users\VELOXSHOP\Downloads\dumpfilename.sql has finished with 1 errors
How do I allow acess to that table?
You'll need to make a new dump/backup of your old database, this time remove those innodb tables from your target. You can do this by using --ignore-table parameter on the command line:
mysqldump -u root -p --all-databases --ignore-table=mysql.innodb_index_stats --ignore-table=mysql.innodb_table_stats > dump.sql
Then you should be able to restore your backup on the new database using the command below:
mysql -u root -p < dump.sql
You can also circumvent this error using the --force option which causes mysql client to continue despite errors.
Try to add -f to your command like so:
mysql -u root -p -f < dump.sql
-f means --force.
This did the trick for me!
It seems to be restricted in Mysql 8. Remove the insert statement from the sql file. You may have to use sed if the file is very large
https://stackoverflow.com/a/26379517/1106420
https://bugs.mysql.com/bug.php?id=92675
That is a MySQL system table and it's unlikely that you should be inserting records into it directly. MySQL should update the table when it calculates new statistics for indexes when thresholds pass.
Inspect line 318 and figure out why it's trying to insert into that table.

Copying a mysql database generates "ERROR: unknown command" when importing

I'm on a japanese system using xampp. This is the line I use to dump my database.
c:\xampp\mysql\bin>mysqldump.exe -uroot wp_newsja > dump.sql
Then I create a database on another server.
c:\xampp\mysql\bin>mysqladmin -uroot create db
But when I try to execute the sql...
c:\xampp\mysql\bin>mysql -uroot db < dump.sql
... I get the following error.
ERROR at line 145: Unknown command '¥''.
On a japanese computer windows path slashes / are represented with "¥". Which leads me to believe this is an utf8 issue. Maybe there is a way I can mysqldump with some utf8 flag? Thanks for any assistance! The exported sql is here: http://goo.gl/7MPVG - Error at line 145:
edit: Problem solved:
mysql --default-character-set=utf8 db < dump.sql
Sorry if I wasted anyone's time.
mysql --default-character-set=utf8 db < dump.sql
You can add this argument --default-character-set=utf8 in the command:
mysql -u USERNAME -p my_database --default-character-set=utf8 < "C:/My Document Names Have Spaces/my_dump.sql"
I've finally found this solution and it works fine with my new installed WampServer 2.5. I've also tried to add the default character setting in my.ini, but it's useless. Until I've tried the above argument added in my DOS batch file.
My batch file execute the command, like this way:
7zip x -so %1.%2.7z|%mysql% -uxxxx -pyyyyy %2 --default-character-set=utf8
For example, the 7zip filename is 20141231.google.7z, which contains "google.sql", and the database name is google
My backup process on Linux system was a 7zip compressed. In Winodws, I used an automatic batch file to restore the same contents, so that I can share the same database in my biz trip and work offline from the server.
Hope this method is helpful to you.

Import SQL file into mysql

I have a database called nitm. I haven't created any tables there. But I have a SQL file which contains all the necessary data for the database. The file is nitm.sql which is in C:\ drive. This file has size of about 103 MB. I am using wamp server.
I have used the following syntax in MySQL console to import the file:
mysql>c:/nitm.sql;
But this didn't work.
From the mysql console:
mysql> use DATABASE_NAME;
mysql> source path/to/file.sql;
make sure there is no slash before path if you are referring to a relative path... it took me a while to realize that! lol
Finally, i solved the problem. I placed the `nitm.sql` file in `bin` file of the `mysql` folder and used the following syntax.
C:\wamp\bin\mysql\mysql5.0.51b\bin>mysql -u root nitm < nitm.sql
And this worked.
If you are using wamp you can try this. Just type use your_Database_name first.
Click your wamp server icon then look for MYSQL > MSQL Console then run it.
If you dont have password, just hit enter and type :
mysql> use database_name;
mysql> source location_of_your_file;
If you have password, you will promt to enter a password. Enter you password first then type:
mysql> use database_name;
mysql> source location_of_your_file;
location_of_your_file should look like C:\mydb.sql
so the commend is mysql>source C:\mydb.sql;
This kind of importing sql dump is very helpful for BIG SQL FILE.
I copied my file mydb.sq to directory C: .It should be capital C: in order to run
and that's it.
In windows, if the above suggestion gives you an error (file not found or unknown db) you may want to double the forward slashes:
In the mysql console:
mysql> use DATABASE_NAME;
mysql> source C://path//to//file.sql;
Ok so, I'm using Linux but I think this holds true for Windows too.
You can do this either directly from the command prompt
> mysql -u <user name> -p<password> <database name> < sqlfilename.sql
Or from within the mysql prompt, you can use:
mysql>source sqlfilename.sql
But both these approaches have their own benefits in the results they display.
In the first approach, the script exits as soon as it encounters an error. And the better part, is that it tells you the exact line number in the source file where the error occurred. However, it ONLY displays errors. If it didn't encounter any errors, the scripts displays NOTHING. Which can be a little unnerving. Because you're most often running a script with a whole pile of commands.
Now second approach (from within the mysql prompt) has the benefit that it displays a message for every different MySQL command in the script. If it encounters errors, it displays the mysql error message but continues on through the scripts. This can be good, because you can then go back and fix all the errors before you run the script again. The downside is that it does NOT display the line numbers in the script where the errors were encountered. This can be a bit of a pain. But the error messages are as descriptive so you could probably figure out where the problem is.
I, for one, prefer the directly-from-OS-command line approach.
If you are using xampp
C:\xampp\mysql\bin\mysql -uroot -p nitm < nitm.sql
You are almost there
use
mysql> \. c:/nitm.sql;
You may also access help by
mysql> \?
For localhost on XAMPP. Open a cmd window and type
cd C:\xampp\mysql\bin
mysql.exe -u root -p
Attention! No semi-colon after -p
Enter your password and type
use database_name;
to select the database you need.
Check if your table is there
show tables;
Import from your sql file
source sqlfile.sql;
I have put my file on C:\xampp\mysql\bin location in order to don't mix up with locations of sql file.
Try:
mysql -u username -p database_name < file.sql
Check MySQL Options.
Note: It is better to use the full path of the SQL file file.sql.
Don't forget to use
charset utf8
If your sql file is in utf-8 :)
So you need to do:
cmd.exe
mysql -u root
mysql> charset utf8
mysql> use mydbname
mysql> source C:\myfolder\myfile.sql
Good luck ))
In Linux I navigated to the directory containing the .sql file before starting mysql. The system cursor is now in the same location as the file and you won't need a path. Use source myData.sql where my date is replaced with the name of your file.
cd whatever directory
mysql - p
connect targetDB
source myData.sql
Done
from the command line (cmd.exe, not from within mysql shell) try something like:
type c:/nite.sql | mysql -uuser -ppassword dbname
Does your dump contain features that are not supported in your version of MySQL? You can also try to remove the starting (and ending) MySQL commented SET-statements.
I don't know if your dump comes from a Linux version of MySQL (line endings)?
I have installed my wamp server in D: drive so u have to go to the following path from ur command line->(and if u have installed ur wamp in c: drive then just replace the d: wtih c: here)
D:\>cd wamp
D:\wamp>cd bin
D:\wamp\bin>cd mysql
D:\wamp\bin\mysql>cd mysql5.5.8 (whatever ur verserion will be displayed here use keyboard Tab button)
D:\wamp\bin\mysql\mysql5.5.8>cd bin
D:\wamp\bin\mysql\mysql5.5.8\bin>mysql -u root -p password db_name < "d:\backupfile.sql"
here root is user of my phpmyadmin
password is the password for phpmyadmin so if u haven't set any password for root just nothing type at that place,
db_name is the database (for which database u r taking the backup)
,backupfile.sql is the file from which u want ur backup of ur database and u can also change the backup file location(d:\backupfile.sql) from to any other place on your computer
mysql>c:/nitm.sql;
That would write the output of the mysql command to 'nitm.sql;' (What's the ';' supposed to do?) Assuming you've got a copy of the original file (before you overwrote it) then:
mysql < c:/nitm.sql
Export Particular DataBases
djimi:> mysqldump --user=root --host=localhost --port=3306 --password=test -B CCR KIT >ccr_kit_local.sql
this will export CCR and KIT databases...
Import All Exported DB to Particular Mysql Instance (You have to be where your dump file is)
djimi:> mysql --user=root --host=localhost --port=3306 --password=test < ccr_kit_local.sql
In Windows OS the following commands works for me.
mysql>Use <DatabaseName>
mysql>SOURCE C:/data/ScriptFile.sql;
No single quotes or double quotes around file name. Path would contain '/' instead of '\'.
For those of you struggling with getting this done trying every possible answer you can find on SO. Here's what worked for me on a VPS running Windows 2012 R2 :
Place your sql file wherever the bin is for me it is located at C:\Program Files\MySQL\MySQL Server 8.0\bin
Open windows command prompt (cmd)
Run C:\Program Files\MySQL\MySQL Server 8.0\bin > mysql -u [username] -p
Enter your password
Run command use [database_name];
Import your file with command source C://Program Files//MySQL//MySQL Server 8.0//bin//mydatabasename.sql
It did it for me as everything else had failed. It might help you too.

using mysqldump to restore database to mysql located on another computer

Any idea how to do this restore ?
I looked into help of mysqldump but couldn't see it there .
If so can you give me some example.
With mysqldump you will generate a script you can use for restore on a different computer like this:
$ mysql -U user_name < your_backup.sql
Run on your favorite shell (windows command prompt, bash, csh...).
I think you can use CMD to navigate to the mysqldump location, then type this command,
mysqldump database_name -u username >location\to\save\dump.sql
change database_name to the database you want to backup, username to the username associated with the database, and location\to\save\dump.sql to the location where you want to save the output sql file, for me I wrote it D:\dump.sql
Then on the other machine you can import the SQL file using the PHPMyAdmin.
You can just execute the SQL using the mysql command-line command. There is a switch to specify which file to import, I think it is -I but I'm not sure.
It's just plain SQL. Pass the file to mysql (the mysql command line tool) and it will execute it:
mysql < backup.sql
From the shell prompt, using
parameters form the mysqldump
doc, mysqldump the database using a > redirect to a
human readable .sql file. E.g.
$ mysqldump --databases src_db > src_db.sql
Transfer the human readable file to
another machine.
After making sure the destination database exists has been created, redirect < the .sql file into the destination database.
$ mysql dest_db < src_db.sql

mysql import on windows

I have a MySQL file, db.sql. I have tried to import it using:
mysql -uroot -p[password] db < db.sql
All I get is a listing of mysql commands, or I get a syntax error. The weird thing is I used this file last week and, as far as I know, I'm doing it the same way.
I create the database, then in command line enter the above but it's not working. I've tried being inside mysql and just at command line and nothing seems to be working.
Is there something I should be doing differently in windows or MySQL5? I don't know how the heck I got it to work the first time...
TIA
Try this instead:
mysql -u root -p
(prompts for password)
use db;
source db.sql
I found out it is different to run this command from Windows Command Line (cmd.exe) and Windows PowerShell.
Using CMD.exe the command works okay, but in PowerShell I get this error:
mysql -uroot exampledb < exampledb.sql
The '<' operator is reserved for future use.
Not sure if your example was a typo or not, but for starters you need to have a space in between your flags and their values, roughly like this:
mysql -u root -p [password] db < db.sql
If you are already logged in the try this it will be very useful, but depend upon the MySQL version, it works on MySQL 5.0
For log in if you are not already logged in.
mysql>[your password]
Other wise, use the database to which you want to import the SQLDump file by command.
mysql>use [your database name]
And then give source the database Dump file path as blow command(If not works the copy Dump database file to the bin folder where the MySQL installed for eg. "C:/programfiles/mysql/mqlserver5.0/bin")
mysql> source [dataBasePath+name.sql or dataBaseName.sql]
I've been using PHP script called "BigDump":
http://www.ozerov.de/bigdump.php
This perfectly works
mysql>[your password]
Other wise, use the database to which you want to import the SQLDump file by command.
mysql>use [your database name]
And then give source the database Dump file path as blow command(If not works the copy Dump database file to the bin folder where the MySQL installed for eg. "C:/programfiles/mysql/mqlserver5.0/bin")
mysql> source [dataBasePath+name.sql or dataBaseName.sql]EG: source C:.....sql
I am using mysql server 5.5
In Windows PowerShell, you can pipe in the contents like so:
Get-Content db.sql | mysql -u root -p [password]