I export whole databases sql file from localhost wamp. Now I want to import all databases and table by importing that one sql file. But I get sql error...database error with name...and following error. Plz give me solution for this.
MySQL said:
#1046 - No database was selected
First select your database, then do the import. You can modify your sql file with a use databasename; to select a database for you during import
1046 - No database was selected
This error suggests that when you dumped all these database the resulting .sql file does not contain the required use databasename; between each database restore.
You will have to edit the .sql file and add a use databasename; statement for each database, just before the restore changes the database it is restoring.
Can any one explain how to import a Microsoft Excel file in to a MySQL database?
For example, my Excel table looks like this:
Country | Amount | Qty
----------------------------------
America | 93 | 0.60
Greece | 9377 | 0.80
Australia | 9375 | 0.80
There's a simple online tool that can do this called sqlizer.io.
You upload an XLSX file to it, enter a sheet name and cell range, and it will generate a CREATE TABLE statement and a bunch of INSERT statements to import all your data into a MySQL database.
(Disclaimer: I help run SQLizer)
Below is another method to import spreadsheet data into a MySQL database that doesn't rely on any extra software. Let's assume you want to import your Excel table into the sales table of a MySQL database named mydatabase.
Select the relevant cells:
Paste into Mr. Data Converter and select the output as MySQL:
Change the table name and column definitions to fit your requirements in the generated output:
CREATE TABLE sales (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
Country VARCHAR(255),
Amount INT,
Qty FLOAT
);
INSERT INTO sales
(Country,Amount,Qty)
VALUES
('America',93,0.60),
('Greece',9377,0.80),
('Australia',9375,0.80);
If you're using MySQL Workbench or already logged into mysql from the command line, then you can execute the generated SQL statements from step 3 directly. Otherwise, paste the code into a text file (e.g., import.sql) and execute this command from a Unix shell:
mysql mydatabase < import.sql
Other ways to import from a SQL file can be found in this Stack Overflow answer.
Export it into some text format. The easiest will probably be a tab-delimited version, but CSV can work as well.
Use the load data capability. See http://dev.mysql.com/doc/refman/5.1/en/load-data.html
Look half way down the page, as it will gives a good example for tab separated data:
FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\'
Check your data. Sometimes quoting or escaping has problems, and you need to adjust your source, import command-- or it may just be easier to post-process via SQL.
There are actually several ways to import an excel file in to a MySQL database with varying degrees of complexity and success.
Excel2MySQL. Hands down, the easiest and fastest way to import Excel data into MySQL. It supports all verions of Excel and doesn't require Office install.
LOAD DATA INFILE: This popular option is perhaps the most technical and requires some understanding of MySQL command execution. You must manually create your table before loading and use appropriately sized VARCHAR field types. Therefore, your field data types are not optimized. LOAD DATA INFILE has trouble importing large files that exceed 'max_allowed_packet' size. Special attention is required to avoid problems importing special characters and foreign unicode characters. Here is a recent example I used to import a csv file named test.csv.
phpMyAdmin: Select your database first, then select the Import tab. phpMyAdmin will automatically create your table and size your VARCHAR fields, but it won't optimize the field types. phpMyAdmin has trouble importing large files that exceed 'max_allowed_packet' size.
MySQL for Excel: This is a free Excel Add-in from Oracle. This option is a bit tedious because it uses a wizard and the import is slow and buggy with large files, but this may be a good option for small files with VARCHAR data. Fields are not optimized.
Not sure if you have all this setup, but for me I am using PHP and MYSQL. So I use a PHP class PHPExcel. This takes a file in nearly any format, xls, xlsx, cvs,... and then lets you read and / or insert.
So what I wind up doing is loading the excel in to a phpexcel object and then loop through all the rows. Based on what I want, I write a simple SQL insert command to insert the data in the excel file into my table.
On the front end it is a little work, but its just a matter of tweaking some of the existing code examples. But when you have it dialed in making changes to the import is simple and fast.
the best and easiest way is to use "MySQL for Excel" app that is a free app from oracle. this app added a plugin to excel to export and import data to mysql. you can download that from here
When using text files to import data, I had problems with quotes and how Excel was formatting numbers. For example, my Excel configuration used the comma as decimal separator instead of the dot.
Now I use Microsoft Access 2010 to open my MySql table as linked table. There I can simply copy and paste cells from Excel to Access.
To do this, first install the MySql ODBC driver and create an ODBC connection.
Then in access, in the "External Data" tab, open "ODBC Database" dialog and link to any table using the ODBC connection.
Using MySql Workbench, you can also copy and paste your Excel data into the result grid of MySql Workbench. I gave detailed instructions in this answer.
Fastest and simpliest way is to save XLS as ODS (open document spreasheet) and import it from PhpMyAdmin
For a step by step example for importing Excel 2007 into MySQL with correct encoding (UTF-8) search for this comment:
"Posted by Mike Laird on October 13 2010 12:50am"
in the next URL:
http://dev.mysql.com/doc/refman/5.1/en/load-data.html
You could use DocChow, a very intuitive GIU for importing Excel into MySQL, and it's free on most common platforms (including Linux).
More especially if you are concerned about date, datetime datatypes, DocChow easily handles datatypes. If you are working with multiple Excel spreadsheets that you want to import into one MySQL table DocChow does the dirty work.
Step 1 Create Your CSV file
Step 2 log in to your mysql server
mysql -uroot -pyourpassword
Step 3
load your csv file
load data local infile '//home/my-sys/my-excel.csv' into table my_tables fields terminated by ',' enclosed by '"' (Country, Amount,Qty);
Another useful tool, and as a MySQL front-end replacement, is Toad for MySQL. Sadly, no longer supported by Quest, but a brilliant IDE for MySQL, with IMPORT and EXPORT wizards, catering for most file types.
If you are using Toad for MySQL steps to import a file is as follows:
create a table in MySQL with the same columns that of the file to be imported.
now the table is created, goto > Tools > Import > Import Wizard
now in the import wizard dialogue box, click Next.
click Add File, browse and select the file to be imported.
choose the correct dilimination.("," seperated for .csv file)
click Next, check if the mapping is done properly.
click Next, select the "A single existing table" radio button also select the table that to be mapped from the dropdown menu of Tables.
Click next and finish the process.
If you don't like plugins, VBA and external tools, I have an excel file that using formulas only allows you to create INSERT/UPDATES. You only have to put the data on the cells:
As an extra, there's another tab in the file to CREATE TABLES:
The file can be found on the following link:
EXCEL FILE
I've had good results with the Tools / Import CSV File feature in HeidiSQL, with CSV files directly exported from Excel 2019 with "Save As..."
It uses LOAD DATA INFILE internally but with a GUI interface and also analyzes the CSV file before passing it to LOAD DATA INFILE so it can, for example, create the table using the first row as column names and guessing the column data type (<New table> option as shown in the picture)
I use PHP dbase extention to read dbase files and upload them into MySQP.
My Code:
if(dbase_open($FileDir,0)){
$dbOpen = dbase_open($FileDir,0);
$records = dbase_numrecords($dbOpen);
$qry = "";
$qry = "INSERT INTO ".$Table." (`SCADA`, `Date`, `PlantNo`, `State`, `SubState`, `Frequency`) VALUES ";
for ($i=1; $i<=$records; $i++){
$rows = dbase_get_record_with_names($dbOpen,$i);
$qry .= '('.$SCADA.','.$rows['Date'].','.$rows['PlantNo'].','.$rows['State'].','.$rows['SubState'].','.$rows['Frequency'].'),';
}
$qry = substr($qry, 0, -1);
$Insert = $conn -> prepare($qry);
$Insert -> execute();
Now I have to do the same but with xls files! I know that I can convert them into csv and import them via PHP, but I have 100 xls files... How can I transfer them to MySQL? Ant idea?
Seems you can try use:
1. PHP-EXCEL-READER (http://code.google.com/p/php-excel-reader/)
2. PHPExcel (https://phpexcel.codeplex.com/)
Direct import from Excel to MySQL will not be possible without a third party proprietary product, that you would need to buy like - dbForge Studio or something (I have not tried this one, so I cant even recommend it). Tool called phpmyadmin used to have this functionality, but its depreciated since version 3.4.5, so if you install an old one it might be an option for you. That really depends on several factors.
For a general start, ofcourse, you should make sure that the file you want to import has the same columns, and column order as the database where you want to import it into.
If you convert, or export your xls files into CSV (its a seperate story on how to do that and I will not cover here, plenty of resources or online converters out there), you can merge all of them either in Excel, or from your console. On all modern operating systems you can just put all files in the same directory, cd or dir into it and run "cat *.csv > merged.csv" which will merge all files into one. (copy /b *.csv merged.csv on windows machines)
Once you have a single merged file you can run php to execute the mysql import -
"LOAD DATA INFILE 'c:/path/to/file/merged.csv' INTO TABLE tablename" (more about it here - http://dev.mysql.com/doc/refman/5.1/en/load-data.html)
Ofcourse you can also automate exporting XLS into CSV by using a php library like PHPExcel - https://phpexcel.codeplex.com/
As Cninroh suggests, you'll need a proprietary product. I suggest a product I wrote called Excel2MySQL. It has a simple user interface for manual imports and it also includes a command line interface for automating uploads and can read any excel file directly. No need to export as a csv file. The Excel sheetnames define the destination MySQL table name. The table can be automatically created or simply appended to. All fields can also be automatically optimized to the proper MySQL type. The program is free to try, so you can verify if it will work for you.
-h, --help, display help message and exit
-f file, Excel file to convert (include full path) (REQUIRED)
-s sheet, Excel sheet to convert (omit to convert all)
-z host, mysql server hostname or IP address (omit will default to localhost)
-d database, mysql database name (REQUIRED)
-u user, mysql user name (REQUIRED)
-p password, mysql password
-x port, mysql port number (omit will default to 3306)
-r, replace existing table (omit to append to existing table)
-n, first row is not a header (omit to indicate first row contains header)
-a, allow spaces in table & field names (omit to change spaces to underscores)
-m, use myisam database storage engine (omit to use innodb)
-k, keep blank rows & columns (omit to remove)
-c, Unmerge merged cells
-v, define all fields as varchar type on tables (omit to optimize field types)
Here is an example command line to upload an excel file and all it's sheets to tables:
excel2mysqlCLI.exe -f "c:\my excel.xls" -d mydb -u myid -p mypass
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'm trying to import .sqlite file to sqlite3 im using windows 8 pc,
It's throwing an error of
expected 5 rows found 1-rest filled with null
even my table columns are fine.
can anyone please help me.
thank you in advance.
I think you can try this method. So you don't have to import/export via third-party files such as csv or any additional software. I plan to do this method to periodically copy aquired data in a RAMDRIVE-placed database to the SD-Card. Of course sqlite3 must be able to load your database in your case.
ATTACH DATABASE 'foo.sqlite' AS 'foo';
.databases
INSERT OR REPLACE INTO 'main.mytable' SELECT * FROM 'foo.mytable';
DETACH DATABASE 'foo';
.databases
check here for ATTACH syntax and here for more INSERT variations.
What you can do is use a third party tool called SQLite Database Browser (http://sourceforge.net/projects/sqlitebrowser).
Using the sqlite browser, open your database in old format (.sqlite) and then click File -> Export -> Database to SQL file.
Now, close the database. Create a new database using SQLite Browser (it automatically generates the database in the new SQLite3 format). Once a database is created, use the File -> Import -> Database to SQL file into the new database in SQLite3 format.
You use the PHP sqlite API to use an .sqlite database.
See http://php.net/manual/en/book.sqlite.php
In general you supply the path to your .sqlite file in the sqlite_open() call, see for an example the manual page of sqlite_open:
http://www.php.net/manual/en/function.sqlite-open.php