MySQL insert failure records into another table - mysql

I'm doing db data migration in MySQL.
I have two tables - source (T1) & destination (T2).
I created one insert ignore script to migrate data from T1 to T2. during script run some record might have failed. So I want to capture these failed records in another table and publish the report out of it
Through a stored procedure I'm able to capture errors and inserted to error table.
But as I asked not use stored procedure so is there any alternative way to capture failure records and insert to error table
Thanks in advance

You can log in to MySQL and specify your error log file:
mysql -u user -p 2> errors.log
Once you are logged in, run the commands that you have and all errors will be written into the file.

Related

find out what happened to mysql table

recently I received a task to insert all data in a xls table into a mysql table. so I changed the excel sheet headers to match what was in the mysql table and used csvkit - csvsql to insert the data into the table.
now, the excel sheet had a few columns I did not need and the existing table had also some columns I did not want to fill with anything.
so I converted the excel sheet to csv data and issued a command like this:
csvcut -d ";" -c 2,4,5,6,7,8,9,11,13,14,15,16,17 -x -S Downloads/excel_sheet.csv| csvsql --create-if-not-exists --tables contacts --insert --blanks --verbose --db mysql://root:"password"#localhost/testdb
I should mention that the mysqlserver version located on my working station is:
Server version: 8.0.23-0ubuntu0.20.04.1 (Ubuntu)
and the target machine on where the data were needed is:
Server version: 5.7.33-0ubuntu0.18.04.1 (Ubuntu)
now the unfortunate thing is that after running the command I only did some select to see if the data has been added, I did not bother to check if the table was altered in any way.
a few days ago I was told that the table had lost all the other info and columns that were there before.
I checked and indeed something happened, because I knew the columns that were there and some are now missing.
Question is can I see what happened ? is it because of different mysql server versions ? and more importantly can we get the data back ?
Thanks in advance

How to run a specific migration of an accidentally dropped table

I accidentally dropped a table using the mysql command line. Luckily the table was empty.
But I need this table back. So I would like to re-run only the migration for that table, and not for other tables since these are still present.
When I run knex migrate:latest, it returns "Already up to date". The same if I npm run migrate name-of-specific-miration-file.
I use knex. How can I run only the specific migration file I want it to run?
I got it to work doing the following:
On MySql command line: create table my_table_name (hello text);
In terminal: knex migrate:down name_of_migration_file.js
In terminal: knex migrate:up name_of_migration_file.js

When I try to log into MySQL via command line, keeps saying "unknown database 'magento2'"

When I try to log into MySQL via command line, keeps saying "unknown database 'magento2'"
Any ideas why? Tried as my username and root, getting the same message. If I can't log into mysql, how could I create a database to begin with of that name? So confused.
You should separate between your database application and a logical database. MySQL server is your database application / server.
When you're logging on to MySQL, you're choosing which logical database you would like to work with. A logical database is actually a container of objects such as tables, triggers, views, etc.
So when you see the error unknown database X, it's because you installed the MySQL server, but didn't create the logical database.
To see a list of all logical databases in your server, login to MySQL and run the command show databases;
To create your database, run the command create database magento2;
Now when you login to that database, it should be there and you can start creating your tables and query data from them.
I had the same issue and found that the database name was set in a cnf file. Perhaps you have something similar.

Importing Data into MySQL Database with SOURCE command

I have an existing MySQL database that I want to refresh with data from MSAccess database. I already have the SQL files created from the Access database with all of the insert statements. There are 3 SQL files, the largest of which is 8 MB.
The database is on an AWS server. In the past I've imported data using Sequel Pro from my Mac. This is very slow and subject to session failure.
Now I've figured out how to create the SQL files on my Windows VM and FTP them directly to the AWS server. My intent is to have a stored procedure truncate all tables and SOURCE the SQL files:
SOURCE /home/me/file1.sql ;
SOURCE /home/me/file2.sql ;
etc...
The stored procedure would also do any prep work on the tables and any post-import things needed like fixing foreign keys, etc.
The first problem is that this command doesn't work and causes syntax error:
set autocommit=0 ; source /home/me/CBD.sql ; commit ;
"source" is squiggly underlined and it says "missing colon". This happens whether or not I use the auto commit stuff.
Any ideas how I could do this?
Thanks...

My script can't execute alter database command SQL Server 2008

I created a database then I create a procedure. When I want to alter this database, I got an error while altering this database says:
create/alter must be the first statement in a query batch
If you have more than one statement to run use 'GO' command:
alter database xyz ...
GO
INSERT INTO myTable() ...
GO
etc