I created a test database for my Java program which connects to it. Now I want to use it on another PC without this test database. Is it possible to create an instance of my database to install it on a certain PC?
Notes:
The PC I want to use my Database on has no MYSQL installed
Questions:
How can I setup my database with a batch file?
Do I need to install MYSQL first or is it possible to use my database without it?
If MYSQL needs to be installed, how can I do it and how can I include my already created tables via batch file?
Edit:
We already have the tables but a new database should be installed on when the program starts the first time.
Yes. You can import your data on PC without installation of MySQL using mysqlimport.
shell> mysqlimport [options] db_name textfile1 [textfile2 ...]
There are many options available for mysqlimport. See here mysqlimport --help, -?.
NOTE : It uses .txt file.
Related
I am using MYSQL Workbench and I want to clone a database on the same server with different name. It should duplicate the all the tables structure and data into the new database.
I know the usual way is probably using data export to generate a sql script of the database and then run the script on the new database but I encounter some issues with it.
Anyway, is there any better way or easier way to do so?
You can use migration wizard from MySQL Workbench. Just choose the same local connection in both source and target selection, then change schema name on manual editing step. If nothing appears on manual editing step click next and the source and targets will appear. Click slowly on the source database name and edit to the correct name. Go thorough to the end and voilĂ - you have two identical databases with different names. Note you must have created the target database already and granted permissions to it for the MySQL Workbench user.
I tried to do it in MySQL Workbench 8.0. However I kept receiving an error regarding column-statics. The main idea is to use mysqldump.exe, located in the installation directory of MySQL Workbench, to export the data. So, supposing a Windows oriented platform:
Open Powershell, navigate to mysqldump.exe directory. In my case the command is:
cd C:\Program Files\MySQL\MySQL Workbench 8.0 CE
Export database by executing mysqldump providing the right arguments:
./mysqldump.exe --host=[hostServerIP] --protocol=tcp --user=[nameOfUser] --password=[yourPassword] --dump-date=FALSE --disable-keys=FALSE --port=[portOfMysqlServer] --default-character-set=utf8 --skip-triggers --column-statistics=0 "[databaseName]"
Without changing directory, import the exported file (.sql) by using the following command in Powershell:
Get-Content "[pathToExportedDataFile]" | ./mysql.exe --user=[nameOfUser] --password=[yourPassword] --port=[portOfMysqlServer] --host=[hostServerIP] --database=[nameOfNewDatabase] --binary-mode=1
You can check in the documentation here for more information regarding the mysqldump options.
Please note the following:
Do not forget to replace the values in [] with your own values and remove the []. Do not remove the quotes("") where the are present.
Do not switch Powershell for cmd or something like git-bash, since the above will not work.
As far as step 3 is concerned, I created the new database from MySQL Workbench and then ran the powershell command.
List item First, create a new database using CREATE DATABASE statement.
Second, export all the database objects and data of the database from which you want to copy using mysqldump tool.
Third, import the SQL dump file into the new database.
Situation: I have 2 servers, one of them currently hosting a live WordPress site, and I want to be able to transfer the site to the other server in case the first server goes down. Transferring the source files is easy; transferring the database is what I need to figure out how to do. Both of the servers are Windows Server 2008.
Is there any easy to do this?
Simplest way would be to mysqldump the database, transfer it using the same mechanism you have for your source files, then import it into mysql.
Dump the primary database...
mysqldump -u user -p database > c:\somedir\backup.sql
...transfer the sql file...
Import on the failover...
mysql -u user -p database < c:\somedir\backup.sql
Both export and import can easily be scripted in batch files.
The easiest way that I know is using the plugin "Duplicator". I used it several times with Apache servers, but as is commented here, seems that three years ago it was running ok with Windows 2008 IIS 7, so I figure now it would be better.
Duplicator generates two packages: one with fields (where you can exclude uploads if needed) and the other with the database. Once you have the two packages, you need to upload into your new server and install the package. Of course you need the new database credentials. The plugin ask you in the las step for the new url base to make the adequate substitutions in all the database.
I would like to export a database from PHPMyAdmin (or MySQl Workbench) and import it to a SQLite database so that I can do local editing and testing without screwing up the live version. I am very new to SQL, so all of the export options, etc, are rather dense to me at this point. I have tried using the default export settings PHPMyAdmin with the command
sqlite3 test_db.db < maindb.sql
as well as
sqlite3--> .read maindb.sql
But these throw a bunch of syntax errors and 'no such table' errors.
I have also tried the oft-cited script script found here, but when I try to run this using an export from MySQL Workbench, using the command:
943776/mysql2sqlite.sh maindb.sql | sqlite3 test_db.sqlite
I get the following error:
mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2) when trying to connect
Am I not configuring the exports correctly?
Please see that the referenced script connects to the database server itself. It does not expect a dump!
./mysql2sqlite -h example.com -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
This is the way the script should be executed. With host, username, passwort and the mysql database you would like to dump.
Since database dumps and DBMS features can be severely different between different DBMS (like MySQL and sqlite3), I would recommend to install a local MySQL server instead of using sqlite3. What advantage have you achieved when you make changes to sqlite3, which you cannot apply to the MySQL production database without changes?
An alternative solution is to export an sql dump of your database and then import it back into phpLiteAdmin. From there you can manage your sqlite database inside your browser. When you want to export it, just open the folder where the database is stored and copy the database file.
This solution does not require messing around with scripts, and it's especially handy if you're on a Mac and you're using MAMP, since phpLiteAdmin comes preinstalled with it.
i have my windows form application in my home pc. i want to migrate it to my college PC.how to transfer MySQL database using GUI from one pc to another both running windows
I've never worked with mysql-workbench, but here's a fast and simple solution using the commandline:
Export
mysqldump -u [uname] -p db_name > db_backup.sql
Import
mysql -u username -p -h localhost DATA-BASE-NAME < db_backup.sql
Only for MyISAM tables, you can simply copy and paste the three files that you will find in the database folder inside 'C:\xampp\mysql\data' or similar.
These files have the extensions, .frm, .MYI and .MYD
Once you've pasted the files flush the tables via command or a GUI tool and you have a duplicate of the table on the original machine.
For more about these files see, http://en.wikipedia.org/wiki/MyISAM
If you prefer a more graphically oriented way of doing that use MySQL Workbench -> Management -> Data Export on the source machine. Likewise -> Data Import on the target box. It allows you to easily select individual tables/schemas, creates a self-contained dump file or individual files for each table in case you want to have greater control over what to import etc.
i finally figured out the problem..
i first exported the data using the tab on the left hand side
i selected the appropriate location for the exported file to be saved.(it created an sql query files of the database)
i then copied it to my pen drive and pasted it on the other PC
i installed workbench on the destination PC and imported the sql files but couldnt execute them. it said you dont have a connection something like that. i then searched for servies on my pc in that i got a list of all the services on my pc. search for mysqlxx(where x= integer) right click on it and select start.
then go back to the workbench and execute the sql file the file will execute successfully but you wont be able to see the database.
close workbench and reopen it you now will be able to see the database
I have a mySQL database on my Windows PC. I'm pretty sure I've found the relevant files, namely the following:
formula.frm
formula.ibd
db.opt
What is the natural way to inspect, edit, and generally play with the contents of these files?
You do not view the binary database files directly. MySQL is a service that you connect to with a client and then perform SQL commands. You will need a client (such as MySQL Workbench) to work with the server.
MySQL Workbench is the GUI tool that allows you to connect to a MySQL database and perform actions on it including querying and creating/modifying the various parts of the database.
MySQL Workbench intro: http://dev.mysql.com/doc/workbench/en/wb-intro.html
Getting started with MySQL: http://dev.mysql.com/doc/refman/5.6/en/tutorial.html
There is also the command-line utility that is included when you install the server. It will be in the BIN folder of the MySQL install directory.
Command-line client info: http://dev.mysql.com/doc/refman/5.1/en/mysql.html
Use a tool like Mysql Workbench to connect to the DB. You do nothing directly to the files. You connect to the service and use the DB.
William, it sounds like your question is "how do I take mysql binary files and turn them into something usable on my machine?". If that's the case, you'll want to first install MySQL on your machine if you haven't already. Then you might have a look here for how to recreate a database from a .ibd file.