import the data to db in mysql - mysql

I have sql data in .sql format. and I need to import it to the MySql database. What are all the steps should I take.
Thanks in advance.

Your .sql file only contains a lot of SQL queries.
The simplest way to import your file is to execute those SQL queries, with the mysql command-line tool :
mysql --user=USER --password=PASSWORD --host=HOST DB_NAME < your_sql_file.sql
This will send all the content of your_sql_file.sql to the mysql program, which will execute it -- and, so, import your data.
Of course, you'll have to replace the upper-case USER, PASSWORD, HOST, and DB_NAME with your real connection informations.

Are you using any software to connect with mysql? If yes, then there should be opion for importing data. Try that.

Related

upload large database file to the server

I have 5GB database that needs to be uploaded to phpmyadmin and that too on the shared server where i cannot access the shell.Is there any solution that can take lesser time to upload? Please do help me by providing the steps to upload the sql file. I have searched through internet but could not find an answer.
Do not use phpmyadmin.
Assuming you have shell, upload the file and feed it directly to mysql command.
Your shell command will look like:
cat file.sql | mysql -uuser -ppassword database
or you can do gzipped file:
zcat file.sql.gz | mysql -uuser -ppassword database
Prior doing this check:
database connection works (correct database, user and password)
database is empty :)
mysql max packet size is OK
you have enough diskspace
* UPDATE *
You said you do not have shell access.
Then you have following options -
upload the file and contact support, let they do it for you.
feed it remote, cpanel have special menu where you can get remove access, other panels have same ability too.
in this case code will be executed on your computer and look like:
cat file.sql | mysql -uroot -phipopodil -hwebsite.com
or for windows:
/path/to/mysql -uroot -phipopodil -hwebsite.com < file.sql
do some "hack" - feed it through crontab, at or via php system() command.
If you choose "hack" option, note following:
php have max_execution_time - even if you set it to zero, there could be some limit "imposed" from hosting.
usually hosts have limited mysql updates per hour.
there could be some ulimit restrictions.
if you execute feeding of 5 GB on shared server, server will slow down and administrator will check what you are doing.
This depends on your database, you tagged it with 3 different database types, mysql, sql-server, and postgresql. I know mysql and postgresql have import features, although I'd be surprised if SQL Server didn't as well. You could import the database file via the command line instead of having to use phpmyadmin.
Incidentally, the phpmyadmin tool also has an import feature, but that again depends on the format of your database. If it's a compatible sql file, you could upload it to phpmyadmin and import it there, but I'd recommend the previous method I mentioned, upload it to your host, then use whatever database tool (mysqlimport for mysql, or if it's the result of a pg_dump command, you can just run:
psql <dbname> < <yourfile>
ie
psql mydatabase < inputfile.sql

Can i import a .sql file from wamp to xampp?

i have a .sql file that was exported from wamp, my friend only uses xampp. Is it possible to import my .sql file to xampp?
Yes because the .sql file is most likely independent of the server stack.
Of course it is possible, when wamp give you a export of .sql, this file can be used with all standard web server. (xampp)
I think this may help
Depending on the tool and parameters used to create the .sql dump file of multiple databases, the file will normally have
CREATE DATABASE DBn...;
and
USE DBn;
statements that will allow your import to proceed without hiccups. For example, both the mysqldump command mysqldump command and phpMyAdmin's Export function for multiple database insert them.
Assuming you have exported with a sensible tool like those above, then you can import the database with a command line like this:
mysql -u username -p < dumpfile.sql
Your mysql username account needs to have appropriate privileges to, for example, create databases.
You can even run this command in a more familiar way by naming the startingDB database to use before running the commands in dumpfile.sql:
mysql -u username -p startingDB < dumpfile.sql

How to import a 600mb .sql file in phpMyAdmin by typing command?

I want to import a 600mb .sql file into phpMyAdmin. As I have memory limitation in server, I can't use import option given in phpMyAdmin.
mysql -u username –-password=password database_name < file.sql
If it's not clear, look for how to load from a dump file.
mysql -u [username] -p [dbname] < [path for the sql file to be imported]
You can use this in mysql command prompt.
PHPMyAdmin Can only do this if the server settings are sufficiently generous to allow you to upload such a large file.
If you have command line client then you should use the mysql client. If you don't have command line access then MySQLDumper is a very good tool for importing large SQL files.
If you have memory limitations in the server and you are using phpmyadmin, you have to manually split the sql file or use a tool to split the file based on your memory restrictions and import file by file.

How to import mysql dump to SQLyog

I have few sql dump files like the tables taken from other db. Now i want to update the tables into my server using the sqlyog. So can anyone help me out in importing .sql files into the SQLyog ???
Thank u in advance
In SQLyog there is an option - Tools -> Execute SQL script. You can use this to run SQL scripts.
In order to make it clear please refer the screenshot:
Why use SQLYog, mysqldump is already an available command with server.
mysqldump --opt --user=username --password database > dumbfile.sql
where dumbfile will be your sql file.
MYSQLDump command I have used it a lot to get databases export and is highly reliable.
And mysql command to import the same:
mysql -u root -p[root_password] [database_name] < dumpfilename.sql
In SQLyog there is an option - Tools -> Execute SQL script. If there are some Errors it will give you a pop up, then click on the "Open Error File button", it will give you error in the sql file.
I think you can open your SQL file in Query window, and just run it in SQLYog. Have a look at this documentation page - Executing SQL Queries.
Also, you can use mysql — The MySQL Command-Line Tool, or dbForge Studio for MySQL (free express edition) to execute SQL files against the MySQL database.
In SQLyog v7.14, run DB -> Restore from SQL Dump..., or just press Ctrl+Shift+Q.

convert sqlite file into mysql

I have a .sqlite file which I want to convert into mysql. So is there any way to convert it into mysql?I am using ubuntu. So is there any shell script to change it. Any help will be highly appreciable.
assuming your sqlite db file is login.db
download this script as sqlite3-to-mysql.sh
this command will tranform your sqlite db file to standard mysql sql file: sqlite3 login.db .dump > sqlite.sql && bash sqlite3-to-mysql.sh sqlite.sql > mysql.sql && rm sqlite.sql
import to mysql: mysql -uuser -ppassword -D database < mysql.sql
I've tried this recently and most answers don't work because they're out of date. e.g. python vs python3
A method that worked for me that should never go out of date is to export the tables to CSV and then import them as CSV. I used Sequel Pro which can import a CSV. The downside is that you need to do each table individually. The upside is that this is a very robust method and doesn't require any custom scripts.
Run the following in your database folder changing "thedatabase" and the two occurances of "thetable" to the database name and table name respectively:
sqlite3 -header -csv thedatabase.db "select * from thetable;" > thetable.csv
For Sequel Pro:
Create your database
(Optional: Create table structure. Recommended to have the correct column types) You could get the create statement from an sqlite dump and fix them for mysql.
File > Import
Format: CSV
Check: "First line contains field names"
Check the field mappings and import
Explanation of the command to export:
"sqlite3" is the command line client for sqlite databases.
"-header -csv " sets the output to csv
"thedatabase.db" is the database file
"select * from thetable;" is the query to select all data from the table
" > thetable.csv" redirects the output of the data to thetable.csv file
1) Export sqlite database to sql file
sqlite3 sqlite.db .dump > mysql.sql
2) Import mysql.sql file to mysql database using phpmyadmin or other tools.
To directly import it to the database in just one command:
sqlite3 database.db .dump | mysql -uuser -ppassword database
Google "sqlite to mysql" will give you a lot of articles doing that ...
Okay, easiest is to open the .sqlite file using sqlite, .dump to a file, and the file is a text file containing SQL statements.
You shall be able to edit that file and run in your mysql DB thereafter.