Importing a MySQL Table from one server to another server - mysql

I need to import the table from One MySQL server to another MySQL server. The requirement looks pretty simple but i tried two ways and unable to import the data. Please find the below details and methods I tried to import the data.
We have an existing table in Server A with Engine Type as MyISAM, No primary key and contains duplicate records.
Now, We need to export this table into a new MySQL server (Server B) but the new MYSQL DB has some rules.
Engine should be InnoDB
Every table should contains a primary key.
The below ways i tried to import and failed.
Method 1:-
Exported the data from server A with Outfile command using MySQL Workbench
and tried to import with Infile command but due to the "mandatory primary key" validation all the
rows were not inserted. So to avoid this added an incremental column in new table and tried to
import but again it's failed due to the no.of columns mismatch error
Method 2:-
Configured both the servers in MySQL WorkBench and exported the table in Server A
with MANAGEMENT-> Data Export and tried to Import with MANAGEMENT-> Data Import/Restore
but due to the engines mismatch between the two tables again it's failed to import the data.
(Tried with Dump project folder and self contained folder).
AFAIK, Now I'm left with only one option (which I don't want to do due to the huge data).
Export the data as a CSV file and Import it by using Table Data Import Wizard.
Please guide me is there any other option to import the Data.

What you can try is to add the new auto inc column to your source table (and add the primary key also, to check if there's no problem). To make this complete you can also convert the table to the InnoDB engine and have it so prepared to be copied over with the least friction.

Related

data migration from mysql to mongodb, i have issue with convergion between IDs

I'm making data migration from MySQL to MongoDB and it's my first time, I followed these steps:-
select all data from SQL in the specific table and save it in one .CSV file.
set headers to the file data so every object has a key.
import the .csv file to DB using MongoDB compass.
the problem is the IDs in SQL away different from the MongoDB objectId, so how can I handle this?
note that the old database "SQL" has primary and foreign keys and my MongoDB schema has references too using objetcId.

Mysql LOAD DATA IN FILE discard file like Oracle Sql Loader does

I have to load several CSVs into some tables with Mysql LOAD DATA IN FILE, and I want to save discard records that could not be loaded (Because failed FKs, duplicates, etc.) in a discard file, such as Oracle SQL loader does
Any suggestion?
Thanks!
You can import data easily using MySQL WorkBench using import wizard through CSV. It has the option to import all the data and create new table. From there you can alter the tables later on or make necessary indexes as needed, or change dataTypes on the go.
Another option is to use LOAD DATA commands as usual. Import data to a newly created tables without the foreign keys. You can target csv columns to specific table columns as well. see https://dev.mysql.com/doc/refman/8.0/en/load-data.html

Unable to import data from csv file to mysql workbench on Ubuntu

I am trying to import data from csv file to mysql table using mysql workbench Import/Export wizard to update my table. But The Import option is available only for certain tables while it is not available for some tables though both the tables belonging to same Database with same user privilege access.
I am using mysql workbench version 5.5.49, I just wanted to know why Import option is available for specific tables not for all belonging to same database. Please refer image below:
Check this link https://dev.mysql.com/doc/workbench/en/wb-admin-export-import-table.html
See "Table Data Import Wizard"
Whenever you import from CSV, make sure you select new table. Consider this as temp table. Then you can move data to your required table using insert from table or insert ignore from table
The import option from csv is only available on windows. For linux there are several plugins that would do the trick

Importing data from Excel to MySQL database using SQLyog

Is there a way to automate importing of data from Excel/csv to MySQL database using SQLyog so that it automatically updates every time?
use Database -> Import -> Import External Data
Automatically each time what happens though ? It may be easier using LOAD DATA mysql command on a cronjob.
For an "update" by CSV check out
http://www.softwareprojects.com/resources/programming/t-how-to-use-mysql-fast-load-data-for-updates-1753.html
Step 1: Use LOAD DATA to import the entire input file into a temporary table and update primary key id's for any existing records we already have
Step 2: Use SELECT INTO OUTFILE to write all records we couldn't find an id for (new records) into a temporary text file
Step 3: Use LOAD DATA to add all new records (from step 2) into the target table
Step 4: Use a single UPDATE query, to update all records that match an existing primary key
Sqlyog is a standalone application and can't automate the importing process.
You can create a cronjob for LOAD DATA INFILE command to your server.

How to convert csv into database table

Is there a way to import a csv into a SQL table, without having a previously-constructed table? I know how to import a csv into an existing table, but is there a way to create one from the csv?
You can do this using phpMyAdmin ,
(in this method csv file first row elements use as column names for the sql table)
1) select database
2) go to import tab and select csv file
3) ↓↓↓↓↓↓↓
4) after above steps new table will be created and if you want to change table names instead of having table1,table2
select table and go to operation tab :)
(phpMyAdmin 4.1.14)
I am no expert in MySQL but I don't believe there is such an import process. And there might not be in other database servers like Oracle, SQL Server, or PostgreSQL. In fact, it may not be a desirable automation as a table should be user defined and created to fit the database's relational model and for appropriate data types, indices, and keys.
Almost all SQL dialects require setting up the database table beforehand. If not, how would the system know beforehand you intended an integer or long number, a double or decimal number, a tinytext or longtext, which fields are to be indexed, or serve as primary key, and so on?
You might argue MS Access allows a CSV import with an optional table name. However, the ribbon wizard walks the user through setting up the field types, primary key, and table name. And going the non-wizard automation route, the DoCmd.TransferText method requires table name when using the acImportDelim argument.
So, your best process in MySQL may be LOAD DATA INFILE to run a bulk import of an external CSV into an existing table.