I want to export data from a sql table, but I dont want the primary key to be exported.
The reason is that I have data on my localhost that needs to be inserted in a remote database (remote and local db have the same structure). But on the remote db, the table already has data, and they will be primary key conflicts if I try to add the data from my localhost.
This question has somehow been treated here before: table-without-dumping-the-primary-key.
I used this method in the past, but it's annoying to have to create a new table to make the transfer...
It surprises me that I can't export data from a table while omitting a column, in this case, the primary key column.
Been looking the mysql documentation but it wasn't helpful...
Any idea?
Can you create a VIEW without the primary key, and then export VIEW DATA?
Related
I have an excel file that comes from an export from an online platform. I want to import it into Microsoft Access. Most of the sheets contain data that are unique according to a composite key. However, when I am importing a sheet with the assistant, it is possible to let Access add a primary key, select one field as a primary key or to declare no primary key. There is no option to directly declare a composite key.
I tried to declare no primary key and to open the Create mode to declare the composite key myself. It does work, but when I rerun my saved import, the composite key is lost.
How can I import a sheet with a composite key or at least not lose my composite key when running the saved import? Is this even possible?
I found an answer on another topic that should suit my needs.
Access - Update Imported Data
The idea is to import in temporary tables, where the primary key can be an auto-increment. "Then, run an update inner join query against your final Access table".
It seems that there is no way of importing without overwriting the declared primary keys, but do tell me if you know a way of doing it, I'm still interested.
I'm not validating the answer yet as I didn't test it, but I will come back here when it will be the case.
I have hosted my Laravel project on Shared hosting.
Everything works fine on local but my main problem is in Phpmyadmin when i imported my sql file into it.
In my local i every table has primary key, auto increment and unique id for all the rows in every table. But when i imported sql into cpanel phpmyadmin all the table doesn't have unique id and no option for create edit update and delete.
The two problems are related, something has gone wroing in the import process and you don't have a proper primary key defined therefore phpmyadmin won't let you do updates or delete.
How did you export and import the data, please explain step by step so we can help you.
Add id as primary key and auto increment.Then it will show all options.
Note: Its not php issue.
I'm trying to export a fairly complex mySQL database from the working local server to upload on to an online server for collaborators to READ ONLY the data within.
The database has a number of Foreign keys, and every table has a primary key. However, since NO DATA WILL BE ADDED to this dumb "shadow" copy, these are irrelevant, and frankly creating a headache trying to get them to import successfully.
So... IS there a way to export a MySQL databases' structure (and possibly data) withOUT any keys, keeping the autoincrement column, but just treating it like any other INT column, and removing the foreign key constraints?
You can export a MySQL database without AUTO_INCREMENT options this way:
mysqldump --compatible no_field_options ...
I don't know of any way to omit the foreign key constraints. But if you use mysqldump, the export does SET FOREIGN_KEY_CHECKS=0; before creating any tables. This allows tables to be created out of order.
Re your comment:
If you really can't allow foreign key declarations in your table definitions, you'll have to edit them out of the MySQL export file. You can do this manually with any text editor, or else come up with a filter using sed or perl or a variety of other tools.
There's an example of a sed command in one of the answers to How do I dump MySQL file without Foreign Keys via command line?
It might be easier to drop the constraints in your tables before you export the database.
I want to put my live site (wordpress) on localhost, so I exported the database (turning on the options for dropping database and tables) with phpmyadmin. When importing on localhost with BigDump I get the error message that "Multiple primary keys are defined".
How can I solve this?
All the suggestions I have read so far say to drop the tables and/or database when exporting from live site. I did that but it makes no difference. What else can I do to succesfully import the DB on localhost?
Check your create table statements in exported file. May be somewhere in your create statemate two primary keys are defined.
A table can have only one primary key, which may consist of single or multiple fields. When multiple fields are used as a primary key, they are called a composite key.
If possible cereate database and tables manually and remove table creation statements from expoted file and you can source only data from the file.
I'm developing an Android application in which the data is stored in a SQLite database.
I have made sync with a MySQL database, in the web, to where I'm sending the data stored in the SQLite in the device.
The problem is that I don't know how to maintain the relations between tables, because the primary keys are going to be updated with AUTO_INCREMENT, and the foreign keys remain the same, breaking the relations between tables.
If this is a full migration, don't use auto increment during migration - create tables with normal columns. Use ALTER TABLE to change the model after import.
For incremental sync, the easiest way I see is additional column in each MySQL table called sqlite_id and filled with original id. Then you can update references using UPDATE (with joins).
Alternatives involve temporary tables for storing data and an auxiliary table used for pairing. Tedious for bigger data model.
The approach I tend to use, if possible, is to avoid auto increment in such situations. I have usaully an auxiliary table with four columns like this: t_import(tablename, operationid, sqlite_id, mysqlid).
Process is the following:
Import the primary keys into t_import. Use operationid to separate parallel imports if needed.
Generate new keys for data tables and store them into t_import table. This can be combined with step one.
Import the actual data and use t_import for setting new primary keys and restore relations.
That should work for most scenarios I know about.
Thanks or the help, you have given me some ideas.
I will try to add a id2 field to the tables that will store the same value as the primary key (_id)
When I send the information from SQLite to MySQL and the primary key is incremented I will have the id2 field with the original value of the primary key so that I can compare it with the foreign key of the other tables and update it.
Let’s see if it works.
Thanks