I'm struggling to use the Workbench software for a database saved on my desktop. I do normally work with SQL server online but in our case the client sent us directly the local file.
Do you know how if it is possible?
Thanks
NC
create a new database
create database database_name
import the '.sql' file provided to you into it
mysql -u username -p database_name < path/to/database_file.sql
the database will be visible then.
you can use the workbench gui instead. ensure you have created a new database first then import.
Related
I've downloaded sample database, which is currently in my Downloads folder. How to connect it with MySQL console so I could test some queries?
Every tutorial I've seen so far is about how to make your own database and then test queries.
I assume you are talking about the "employees" sample?
That is a (zipped) SQL file, which you can load into MySQL by running
mysql < employees.sql
After unzipping. Eventully you also have to provide -u root as username and -p so it asks for a password.
If you use a GUI like MySQL WorkBench it has a menu entry to import SQL scripts.
See also https://dev.mysql.com/doc/employee/en/employees-installation.html and
https://dev.mysql.com/doc/refman/8.0/en/mysql.html
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
Let's say I remote from my workbrench to the database which is on server now for some reason I need to have copy of the database on my another computer as a local database. How can I do that?
Export it to a single file (whatever.sql), then import it by running the script on your local computer.
There's a "Data Export" link on the left side if you connect to the remote server using MySQL Workbench. Click on that and go through the export process. Then connect to your local server, click on "Data Import/Restore", and choose the file you just saved.
First export data from database, then import database or specific table import in local server.
$ mysqldump -u [uname] -p[pass] [dbname] > [backupfile.sql]
To dump all MySQL databases on the system, use the --all-databases shortcut:
$ mysqldump -u root -p --all-databases > [backupfile.sql]
Source :How to Copy (Backup) a MySQL Database
In addition to a dump and restore you can try the MySQL Workbench migration module which allows to migrate from MySQL to MySQL (useful for instance to upgrade from a previous version or to copy a schema, as in your case).
MySQL Workbench migration (general description, video tutorial, white paper): http://www.mysql.com/products/workbench/migrate/
The MySQL Workbench migration wizard: http://dev.mysql.com/doc/workbench/en/wb-migration-wizard.html
I asked this question 1 hour ago:
How can I transfer my data from one database(000webhosting.com) to another(shatellhost.com)? note: I use 000webhosting.com free hosting service and I can't create full backup. my data is phpfox social networking.
No one answered so I did this:
I transfered (download) whole data in public-html in 000webhosting.com to my computer and then uploded whole that to public-html of my new host in shotellhost.com, then when i try to open my site: www.ibiology.ir this appears:
Cannot connect to the database:
Can't connect to MySQL server on 'mysql5.000webhost.com' (4)
How can i change MySQL address to new MySQL?
Do a mysqldump and then import the SQL into your new database.
backup: # mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
restore:# mysql -u root -p[root_password] [database_name] < dumpfilename.sql
This error appears to be due to the configuration file of your PHP code, the connection information did not changed properly when you change the host.
First thing to do is make sure that you have change your database. Because of the security reason, most hosting service does not allow connecting to there mysql server from another location. There for, you connect to the mysql5.000webhost.com from another server.
Second, review the code to find out which file containing the database connection information, which usually includes: database hostname, database username, database password, database name. If you use an PHP framework, check the documentation.
In general, this is what I usually do when moving a site to another host:
Open the PHPMyAdmin in my old host control panel
Export the full data of the current database. I usually check DROP TABLE/DROP VIEW option.
Save the exported sql file to my local drive
Open the control panel of my new host
Finding the MySQL configuration option. You may find the MySQL host name here, usualy is localhost (yes, 000webhost is a special case when not use this default host name).
Create the database and the user if necessary.
Write the database hostname, database username, database password, database name information properly into your php configuration file of your source code.
Open the PHPMyAdmin in the control panel of the new host, go to my database (just created) and import the previous sql file.
If everything works well, your code may work.
I have a local MYSQL DB running under WAMP that I need to move up to my production DB server. New to MySQL and need to know the best way to get this DB moved up.
you can run this on your current server:
mysqldump -u user -p database_name > dump.txt
and then do this on your new server:
mysql -u user -p database_name < dump.txt
Replace "user" with your username and "database_name" with a name of your database. You'll be prompted for a password in both cases
Note that second command will replace old tables in your new database
Open up your database in phpMyAdmin and then select Export from the menu. Scroll down and select the Save as file checkbox and then press Go.
Now open up the database in phpMyAdmin on the production server (Note: you will need to create the database first) and then select Import from the menu. Browser to the file you saved and press Go.
If everything goes well you should now have a mirror image of your database on the production server! :)
Do you have phpmyadmin? (If you're not sure, type "http://localhost/phpmyadmin"). If you do, go to "Export on your local computer, and then upload that file on the "Import" section of the remote server. This is the absolute easiest way, and 90% of hosts have phpmyadmin installed.
If you don't, use the command line method suggested by ZeppLock.