I'm using PHPMyAdmin but can use MySQL if it's easier that way, I have quite a large database I'm using for a project that will be updated by uploading .csv files.
However this CSV file will add duplicate data every time, which is no good.
I'm looking to delete all content on the table, but keep the structure and column titles.
Whats the easiest way to do this?
TRUNCATE [TABLE] tbl_name
Go through TRUNCATE TABLE Syntax
Here are the steps :
1.) Go to phpmyadmin
2.) Select db
3.) choose Operations tab.
4.) look for "copy database to" panel
5.) give new database name
6.) select Structure only radio button
7.) select CREATE DATABASE before copying
8.) hit Go button
This will create new database with schema only, which you can rename to your original table name later.
Related
I'm creating an interactive website where the user can upload a file.All I want to do is how can I let the other users see this file? For example if some datas are saved into database I can make this using SELECT and then print these data. But if I have a file how can I make this file to be seen only (not downloaded) from users?
So I just want to know what can I use to make this and don't want you to make this for me! So please if anyone has an ide please tell what should I learn to make this? Is it possible to save the file in a database in phpMyAdmin and to select then? If yes which is the type of the field I should use to save the file so varchar?
It depends on how you want the file to be saved. If it's a text file I would go with text. If it's an image or some other kind of media I would pick blob. You can take a look at What are the differences between the BLOB and TEXT datatypes in MySQL? for more information on MySQL data types.
Another approach would be to save the file somewhere outside the database (in a directory tree somewhere) and save a filepath to that location in a varchar column. Many DBMS do not support group by on blob or clob columns so that is something to consider if portability is an issue, and it adds a layer of separation between your data and file storage.
I have 6 tables already created, which I access from mySQL Workbench. Is there any way I can get the query for the creation of the database and all 6 tables inside it? I need this so that I can create that database and all 6 tables on it, on another computer simply by double clicking an sql file. Thanks in advance :)
If you want to get SQL File from MYSQL Workbench, you need to do this :
Open your model.
Click Database menu and choose Forward Engineer.
And click next until you show like picture below,
Save to file..
I Have created a table on my db, and filled all the records, using CSV file.
I need to do this weekly to keep the table updated.
I want to upload the new records without disturbing the old one onto the same table using csv.
[I have to pick the data from remote host and upload it locally on my server, i dont have access to the remote db]
Kindly guide me.
You can upload records from a CSV into a table VERY quickly using the load data infile syntax (http://dev.mysql.com/doc/refman/5.1/en/load-data.html)
The syntax is pretty simple, but also flexible. This is an example:
LOAD DATA INFILE 'data.txt' INTO TABLE table2
FIELDS TERMINATED BY '\t';
You can kick these off from a console or via code.
This will append to the table, not replace it, so if you don't truncate it first, it should work a charm.
You can of course also load the data manually by parsing the CSV file in your code and manually creating an insert statement for each line of code, but if the format is fixed already, this will be quicker and more efficient.
Edit: It appends the data. By default, no database will delete data from a table unless you specifically tell it to. Any insert statement is what you consider an append statement.
The server I'm using does not allow me to use LOAD DATA INFILE or even save a file as a .txt file. I have a .csv file that is just one column, with a name in each row. I want to insert this data into the name column of a table named people with name as one column and location as the other… where the locations will be updated at a later time.
It's a weird way to do this. But I need to do it this way and not using those previous commands.
Does anybody have any ideas? This has been giving me a problem for many hours. I can't figure out how to load the csv into my table column without using those previously mentioned methods that I can't use on my server.
Based on your issue and lack of general permissions you will have to do the following:
Replace the DOS carriage returns with unix new lines:
$contents=preg_replace('/(\r\n|\r|\n)/s',"\n",$contents);
Save the contents to the file, and then loop through each line, building an INSERT command that you execute to MySQL.
I would like to create a dynamic drop down menu in excel. I am using two sheets, sheet1 having the drop down menus and sheet2 having the reference data. I already did what other excel tutorials said by using a named range and INDIRECT to create a dynamic drop down, but, this is manually done. My data at sheet2 will be coming from mySQL database so the data will vary from time to time and the named reference will be inconsistent. Is it possible to automate this? Can I create a dynamic drop down? By the way, I am using PHP as my server side script which I use to populate my sheet2 with data.
Thanks!
In excel go to the data tab select from other sources: select the connection you want to use. in the properties window, define the table or query which will provide the source data for the dropdown. have the data "refresh" when the sheet opens. The only issue will be saving the password/userid to connect to the dtabase as it is in clear text and anyone can access.