I am using phpMyAdmin to load a CSV file into a MySQL table but, does the table have to be created before the load?
I have read that if the workbench is used ( Import a CSV file into MySQL workbench into a new table dynamically ) the latest version creates the table on the fly but, is this possible with phpMyAdmin.
Here is the code that doesn't work
load data local infile '/Users/...'
into table skin_cutaneous_melanoma
fields terminated by ','
lines terminated by '\n'
Error is:
#1146 - Table hospital.skin_cutaneous_melanoma' doesn't exist
Sure, phpMyAdmin can do this.
From the main page, look for the Import tab. This is, of course, how you expect to import any file including if you already have the database and table created, but if not phpMyAdmin creates a temporary database and table for you using generic names and best guesses as to the data types for your columns. Note that this is probably not the ideal structure, but is the best guess based on the existing data in your database. For best results, you'll probably want to put the desired column names at the top of your CSV file and select the corresponding option during import, or rename them after import (likewise with the database and table names) -- but it is absolutely possible to do the import to a new table.
Related
my Current MySQL table employee_data has 13k rows with 17 columns. The data in the table came from a CSV file Employees.csv. after importing my csv data I added a new column 'password' (so its not in the csv file) Password is edited and accessed via a web portal. I now have an updated csv file and I want to update my main table with that data but I don't want to lose my password info.
Should I import my new CSV file into a temp table in my database and some how compare them? I am not sure where to start and I am open to recommendations.
I am now realizing I should have kept my password info in a separate table. Doh!
I guess I could created a php file that compares each row based on the employee_id field but with 13k rows I am afraid it would time out possibly.
I would do it like this :
Create a temp table using CREATE TABLE new_tbl LIKE orig_tbl; syntax
use LOAD DATA INFILE to import the data from the CSV into the table
Use UPDATE to update the primary table using a primary key / unique column (perhaps employee_id)
I have worked with tables containing 120 million lines and imported CSV files containing 30 million lines into it - this is the method I use all of the time - much more efficient than anything in PHP (and thats my server side language of choice)
Try other tools other than php based ones phpMyAdmin
MySQL workbench is a great tool,
based on you connection it will take a while to query the database with your data.
There are workarounds with php timeout limit,
set_time_limit();
I have a new database table called schools. I have an existing database table on another server that has similar school info that I need. Example: Name, City, State etc., I am using phpMyAdmin to manage this.
My question is... What is the best/detailed way to export the school data from the outside server's database table into the new database table but only extracting and imported the columns I need (example: Name, City, State, etc)?
In SQL, select the data you need,
SELECT (name, city, state) FROM schools
Then in PHP, output it to some format,
$results = $query->fetchAll();
for ($i=0; $i<sizeof($results); $i++) {
# format the output
}
phpMyAdmin has functions to import (and export) data in certain formats including CSV.
You can then import the CSV file to the new server.
You could also do it the other way: save the whole database and import it to the new server. Then delete the columns you dont need with SQL following this syntax,
ALTER TABLE tableName DROP columnName;
If you are using phpMyAdmin then it allows you to export a whole table in SQL format to a downloadable file. That would seem to be the best way to export the data. You can then upload this file to the destination server and import it via phpMyAdmin.
One caveat with this method is that you need to make sure your table names don't clash. If they do, you will need to rename one or the other (I'd suggest renaming the source table before you export it).
Once you've imported the whole table you can do an INSERT INTO...SELECT on the required fields.
I wanted to know if it would be possible to import an excel file into a databse? The columns for the MySQL database would have the same columns that the excel file would have and the title of the excel file.
So for example if I have a file named BL#123456 I would like to be able to take the data in that file and have it outputted to a user as "x y z a b c BL#".
I think I understand the process of data import from excel into MySQL the only thing is the file name to appear along side the columns.
Also I would be using a PHP script to import the data.
EDIT: How do I get it to import the file name as well as the data
Would it work if you did this?
1) create your table (include an additional column for the file name)
2) import a spreadsheet (you probably have collected the file name at this point, so stick it in a variable)
3) after importing each spreadsheet, run an update on your table UPDATE TABLE set fileName = $variable WHERE filename is null
I have been given an excel document which contains information about different embassies, their contact numbers etc. Most of this information is in the database already, but I need to extract one column from this file (emails) and insert it into a specific column (emails) in the database.
Is this possible, or can you only import an exact copy of what you want in the database?
Thanks for any help
Export the table from phpmyadmin as CSV for excel -
drag it into excel -
add the desired column -
Save -
export the table again from phpmyadmin as .sql -
copy the table creation(Not the data) -
delete the table from phpmyadmin-
Run the table creation query so you now have a blank table -
Import the excel csv.
IMPORTANT: backup your database
You may want to make a script with php-excel-reader which goes throught every row in the file, and updates the corresponding database row. I don't think that you can import a file "selectively" in phpMyAdmin.
i have a .csv file containing a table data.I want to dump the total csv file into db using a query in mysql using column name as key...
rather than doing it manually...like using "insert into" query...
if any other language like php or python program make this work...then also ok..
can some one suggest me....pls
you can do this fairly easily with navicat software.
more info here
load data local infile ...
LOAD DATA LOCAL INFILE '/tmp/your_file.csv' INTO TABLE your_table;
You need to ensure the mysql user has enough privileges to perform load