Import/Restore MySQL database? - mysql

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.

Related

Migrate DB from one server Fedora 28 to another Fedora 37

I try to migrate DB from fedora 28 to Fedora 37
I made "mysqldump -u root -p --all-databases > vse.sql"
already done, good.
After copying to new server - I tried to import by command " mysql -u root -p < /vse.sql"
but there is everytime same mistake "ERROR 1050 (42S01) at line 996: Table 'user' already exists"
if I tried this by phpMyAdmin -> same result...
how to force this to overwrite table users with my imported file
I want to migrate all from server one to server two and I dont find another better tool
Adding --add-drop-table to your mysqldump command will generate an export that drops any existing tables that might conflict. This should be used with caution - you'll want to double-check why your new server already has a user table before you go around deleting it.

Losing data when importing database with mysql

I'm trying to import a SQL database with mysql but not all of the rows are imported.
I'm using Ubuntu 17, mysql Ver 14.14, Distrib 5.7.26. First, I'm opening mysql with "mysql -u root -p", then "use db;", then "source [fullpath]/db.sql". Using this I get error message:
ASCII '\0' appeared in the statement, but this is not allowed unless option --binary-mode is enabled and mysql is run in non-interactive mode. Set --binary-mode to 1 if ASCII '\0' is expected
Unfortunately, I check if all tables are imported with "show tables;" and only 2 of 5 tables are imported. Furthermore, not all rows from second table are imported. I'm sure that there must be 5 tables and X number of rows.
To prevent this I used this command:
mysql -u root -p -h localhost -D db --binary-mode -o < [fullpath]/db.sql
But it gives me "ERROR at line 144: Unknown command '\�'."
I've also tried converting database to utf-8 format with this command:
sudo iconv -f utf-16 -t utf-8 db.sql > db_utf8.sql
Then tried using "source" command for "db_utf8.sql" but got this error:
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 42
Current database: db
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 43
Current database: db
ERROR 2006 (HY000): MySQL server has gone away
Please, does someone know what to do.
My coworkers are using the same file and everything is okay for them so maybe I'm not using the correct commands.
Edit: In some questions there are tips about (un)ziping the file but this one was never ziped or unziped.
It works now. I'm lucky that I have a coworker that tried the same and everything was okay. So I mysqldump'ed the database from that computer, moved the .sql file to my computer and tried to import this dumped file. Now everything works fine.

mysqldump: Got error: 1146: Table ' myDatabase.table' doesn't exist when using LOCK TABLES

I'm trying to get dump of my database:
mysqldump myDatabase > myDatabase.sql
but I'm getting this error:
mysqldump: Got error: 1146: Table 'myDatabase.table' doesn't exist when using LOCK TABLES
When I go to mysql:
mysql -u admin -p
I query for the tables:
show tables;
I see the table. but when I query for that particular table:
select * from table;
I get the same error:
ERROR 1146 (42S02): Table 'myDatabase.table' doesn't exist
I tried to repair:
mysqlcheck -u admin -p --auto-repair --check --all-databases
but get the same error:
Error : Table 'myDatase.table' doesn't exist
Why I'm getting this error or how can I fix this error?
I'll really appreciate your help
For me the problem was resolved by going to /var/lib/mysql (or wherever you raw database files are stored) and deleting the .frm file for the table that the errors says does not exist.
I had an issue with doing mysqldump on the server, I realized that tables that if that tables were not used for longer time, then I do not need those (old applications that were shutdown).
The case: Cannot do backup with mysqldump, there are tables that are not needed anymore and are corrupted
At first I get the list of corrupted tables
mysqlcheck --repair --all-databases -u root -p"${MYSQL_ROOT_PASSWORD}" > repair.log
Then I analyze the log with a Python script that takes it at stdin (save as ex. analyze.py and do cat repair.log| python3 analyze.py)
#!/usr/bin/env python3
import re
import sys
lines = sys.stdin.read().split("\n")
tables = []
for line in lines:
if "Error" in line:
matches = re.findall('Table \'([A-Za-z0-9_.]+)\' doesn', line)
tables.append(matches[0])
print('{', end='')
print(",".join(tables), end='')
print('}', end='')
You will get a list of corrupted databases.
Do an export with mysqldump
mysqldump -h 127.0.0.1 -u root -p"${MYSQL_ROOT_PASSWORD}" -P 3306 --skip-lock-tables --add-drop-table --add-drop-database --add-drop-trigger --all-databases --ignore-table={table1,table2,table3 - here is output of the previous command} > dump.sql
Turn off the database, move /var/lib/mysql to /var/lib/mysql-backup, start database.
On a clean database just import the dump.sql, restart database, enjoy an instance without corrupted tables.
I recently came across a similar issue on an Ubuntu server that was upgraded to 16.04 LTS. In the process, MySQL was replaced with MariaDB and apparently the old database couldn't be automatically converted to a compatible format. The installer moved the original database from /var/lib/mysql to /var/lib/mysql-5.7.
Interestingly, the original table structure was present under the new /var/lib/mysql/[database_name] in the .frm files. The new ibdata file was 12M and the 2 logfiles were 48M, from which I concluded, that the data must be there, but later I found that initializing a completely empty database results in similar sizes, so that's not indicative.
I installed 16.04 LTS on a VirtualBox, installed MySQL on it, then copied the mysql-5.7 directory and renamed it to mysql. Started the server and dumped everything with mysqldump. Deleted the /var/lib/mysql on the original server, initialized a new one with mysql_install_db and imported the sql file from mysqldump.
Note: I was not the one who originally did the system upgrade, so there may be a few details missing, but the symptoms were similar to yours, so maybe this could help.

MySQL Dump Error: Lost connection to MySQL server

I have a problem with my SQL database.
My RAID failed but I recover data from the drive and now I have my old database, but it is full errors. I want to export it to SQL file and import it to new RAID and drives. ¨
But when I tried to dump it wit this command:
root#LFCZ:/home# mysqldump -u root -password mc | gzip -9 > mc.sql.gz
It gives me this Error:
mysqldump: Got error: 2013: Lost connection to MySQL server during query when using LOCK TABLES
Can you help with that? Only thing I need is to get .sql file. It is a very big database (approx. 13 GB) but It is running on OVH dedicated server, so it is powerfully enough.

MySQL Data Import Failing With Error -1

I recently backed up a MySQL database in anticipation of a hardware swap out. After installing MySQL on the new hardware I attempted to import the database via MySQL WorkBench. All the tables imported correctly from the complete dump until it hit the Results file – this file contains a number of large BLObs. The preceding Random file which contains smaller BLObs imported correctly. After a number of failures I went to an older dump of individual files with the following result:-
17:35:20 Restoring /media/Week 1/MySQL/Dump20141112/Physio_Results.sql
Running: mysql --defaults-extra-file="/tmp/tmpydQEsK/extraparams.cnf" --host=localhost --user=root --port=3306 --default-character-set=utf8 --comments < "/media/Week 1/MySQL/Dump20141112/Physio_Results.sql"
ERROR 2006 (HY000) at line 51: MySQL server has gone away
Operation failed with exitcode 1
17:35:21 Import of /media/Week 1/MySQL/Dump20141112/Physio_Results.sql has finished with 1 errors
17:36:11 Restoring /media/Week 1/MySQL/Dump20141112/Physio_Session.sql
Running: mysql --defaults-extra-file="/tmp/tmpnAksEb/extraparams.cnf" --host=localhost --user=root --port=3306 --default-character-set=utf8 --comments < "/media/Week 1/MySQL/Dump20141112/Physio_Session.sql"
17:36:12 Import of /media/Week 1/MySQL/Dump20141112/Physio_Session.sql has finished
So obviously the larger BLObs are causing an issue but how do I overcome this? The documentation I looked at only says:-
Error Code: 2006 MySQL server has gone away
which adds nothing!
After increasing maxallowedpacket and netbufferlength I got slightly further, see below. I am unsure where to go next as I seem unable to restore data that I was allowed to export!
16:19:45 Restoring Physio (Results)
Running: mysql --defaults-extra-file="/tmp/tmpyme2U4/extraparams.cnf" --host=localhost --user=root --port=3306 --default-character-set=utf8 --comments < "/home/mjh/Desktop/Dump20141112/Physio_Results.sql"
ERROR 1118 (42000) at line 53: Row size too large (> 8126). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help. In current row format, BLOB prefix of 768 bytes is stored inline.
Operation failed with exitcode 1
16:19:54 Import of /home/mjh/Desktop/Dump20141112 has finished with 1 errors