What to do if Start Import option is not visible in MySQL? - mysql-workbench

As you can see in the below picture, I'm not able to see the "Start Import" option. Can anyone help me with this? And if you see in the second picture where I have hidden my taskbar and I have pointed to the button which I'm looking for. So how can I get that button on the main screen as we can't scroll in the "Data Import" window.

Check if you have an exported file that has only data or both structure and data.
If your exported file only contains data, then check If you exported the database only contains data, then you have to create all the tables inside your new database.
In MySQL Workbench, we can easily export with both Structure and Data.

you can use the PowerShell to import the database instead of mysql workbench,
all you need to do is locate the mysql.exe file on your system, for me its on
C:\wamp64\bin\mysql\mysql5.7.26\bin
so the command would be like this for importation on windows:
C:\wamp64\bin\mysql\mysql5.7.26\bin\mysql.exe -u [db_user] -p[password] -h 127.0.0.1 [db_name] < backup-file.sql
on Linux:
mysql -u [db_user] -p[password] -h 127.0.0.1 [db_name] < backup-file.sql

Related

Saving presto query output to a file

I'm pretty new to PostgreSQL, but I have to query some results using psql in an interactive command line session. I am connecting through a cluster and I would like to extract the output of the query into a file for further analysis.
The command I use to connect is psql -h hostname.with.dbs -p 5432 -U my-username and inside I do the query. But it is not clear to me how to pipe that into a file in my user folder in the machine used to connect to Presto.
If I have to add more details, let me know, as I am not an expert and might forgot to add important information. Thank you all!
I found a solution to that. Basically appending \g file_name; at the end of the query. It saves the file in the directory where I launched the command to connect to the database. I didn't try to add full path to the file name, but I assume it would work as well.

How to restore one database from a .sql file in which there are two databases?

I was sent a .sql file in which there are two databases. Previously, I only dealt with .sql files in which there is one database. I also can't ask to send databases in different files.
Earlier I used this command:
psql -d first_db < /Users/colibri/Desktop/first_db.sql
Databases on the server and locally have different names.
Tell me, please, how can I now restore a specific database from a file in which there are several?
You have two choices:
Use an editor to delete everything except the database you want from the SQL file.
Restore the whole file and then drop the database you don't need.
The file was probably generated with pg_dumpall. Use pg_dump to dump a single database.
If this is the output of pg_dumpall and the file is too big to edit with something like vi, you can use a stream editor to isolate just what you want.
perl -ne 'print if /^\\connect foobar/.../^\\connect/' < old.sql > new.sql
The last dozen or so lines that this captures will be setting up for and creating the next database it wants to restore, so you might need to tinker with this a bit to get rid of those if you don't want it to attempt to create that database while you replay. You could change the ending landmark to something like the below so that it ends earlier, but that is more likely to hit false positives (where the data itself contains the magic string) than the '^\connect' landmark is.
perl -ne 'print if /^\\connect foobar/.../^-- PostgreSQL database dump complete/'

Importing a dump.sql into Postgres Database using command prompt

I'm using my Windows PC, and I'm trying to import a "dump.sql" into the database "TEST" created with Postgres, using command prompt. I do it in two steps:
Step 1:
cd C:\Program Files\PostgreSQL\12\bin
Step 2:
psql -U username -d TEST < C:\Users\Username\Desktop\University\Politechnic\III year\INFORMATIC TECHNOLOGIES FOR THE WEB\PDF SL\SL\Materials\TIW_IOL_ServletJSP\db\dump.sql`
Long path, I know. But the result is: "Impossible to find specified file".
What can I do?
Not sure how security is where you are at, but can you attempt to write to a file with a simpler destination? Such that you take out any possibility of spaces and/or length being the issue? Then you will at least be able to remove those variables or narrow down to them depending on the outcome. Note that the max path length is 260 characters
(From comment on question)

Export and import table dump (.sql) using pgAdmin

I have pgAdmin version 1.16.1 installed on my machine.
For exporting a table dump, I do:
Right click on the table => Choose backup => Set Format to Plain => Save the file as some_name.sql
Then I remove the table.
Ok, now I need to import the backup I just created from some_name.sql into the database.
How am I supposed to do this? I can't find any clear instructions on how to import table's .sql dump into database using pgAdmin.
I'd appreciate some guidance.
In pgAdmin, select the required target schema in object tree (databases ->your_db_name -> schemas -> your_target_schema)
Click on Plugins/PSQL Console (in top-bar)
Write \i /path/to/yourfile.sql
Press enter
An another way, you can do it easily with CMD on Windows
Put your installed version (mine is 11).
cd C:\Program Files\PostgreSQL\11\bin\
and run simple query
psql -U <postgre_username> -d <db_name> < <C:\path\data_dump.sql>
enter password then wait the final console message.
Note: Make sure to remove <> from the above query except for the < between db_name & file path.
Example: psql -U postgres -d dumb_db < D:\db_dump.sql
Using PgAdmin
step 1:
select schema and right click and go to Backup..
step 2:
Give the file name and click the backup button.
step 3:
In detail message copy the backup file path.
step 4:
Go to other schema and right click and go to Restore. (see step 1)
step 5:
In popup menu paste aboved file path to filename category and click Restore button.
Follow the steps in pgadmin
host-DataBase-Schemas- public (click right) CREATE script- open file -(choose xxx.sql) , then click on the option execute query write result to file -export data file ok- then click in save.its all. it work to me.
note: error in version command script enter image description herede sql over pgadmin can be search, example:
http://www.forosdelweb.com/f21/campo-tipo-datetime-postgresql-245389/
Click "query tool" button in the list of "tool".
And then click the "open file" image button in the tool bar.
If you have Git bash installed, you can do something like this:
/c/Program\ Files\ \(x86\)/PostgreSQL/9.3/bin/psql -U <pg_role_name> -d <pg_database_name> < <path_to_your>.sql

convert and import .osm.bz2 to postGis with osm2pgsql fails on Windows

I am new in all this. I followed tutorial http://www.spatialanalysis.ca/2011/using-openstreetmap-data-part1/ and did next:
-installed postGIS/postgreSql, PROJ4;
-saved link from cloudmade;
-create database gis;
and finally did this in cmd
osm2pgsql -d gis -U postgres -P 5432 grad_beograd.osm.bz2
and shows me error Using projection SRS 900913 (Spherical Mercator)
Couldn't open style file '/usr/share/osm2pgsql/default.style': No such file or d
irectory
Error occurred, cleaning up
My OS is WindowsXP.
Asking for help.Thanks advance!
You need to add the -S flag and point to the location of the default.style file - try the osm2pqsql -h command, which will tell you this:
-S|--style Location of the style file. Defaults to
default.style.
Make sure you actually have the file, that tutorial above doesn't really tell you where to get it, I had to do the HOTOSM install to get the default.style file and I just copied it into my folder with the OSM data.
From link http://www.bostongis.com/PrinterFriendly.aspx?content_name=loading_osm_postgis
"If you don't see a default.style file in your package, download it from the above links. For the HOTOSM install, default.style is located in the Program Files/HOSTOSM/share folder. Copy the default.style file into the same folder as your massachusetts.osm.bz2 file.
Note: IF you plan to setup a mapping tile server with OSM data later, check out Dane Springmeyer's Mapnik tutorials: http://www.dbsgeo.com/."