MySQL Databases are one of the many ways to store server data, commonly used by plugins. Show
Your Shockbyte server comes with a free MySQL database that can be used to store new or existing data. If you do not have one yet, you can create a MySQL Database by following this tutorial: Creating a MySQL Database Logging Into phpMyAdminBefore getting started with this tutorial, log into phpMyAdmin where you can manage your MySQL database by following the steps below:
Importing a MySQL DatabaseImporting is a very handy way to store existing data from another server into your server's own database. The steps below will show you how to import an existing MySQL database: This tutorial assumes you already have an existing exported
You're done! You can now use the imported data into your server. Exporting A MySQL DatabaseIf you want to backup of your data or import it into another database, you may do so by exporting your MySQL database.
That's it! You've successfully exported your MySQL database. The exported SQL file is now ready to be imported into another database or simply be stored as a backup. Looking for more MySQL guides? Click here! If you require any further assistance, please contact our support at: https://shockbyte.com/billing/submitticket.php Contents Previous Next last modified July 10, 2020 In this part of the MySQL tutorial, we will be exporting data from MySQL database and importing data back. Simple data exportIn our first example, we will save data in a text file. mysql> SELECT * FROM Cars INTO OUTFILE '/tmp/cars'; Query OK, 8 rows affected (0.00 sec) We
select all rows (8) from the $ cat /tmp/cars 1 Audi 52642 2 Mercedes 57127 3 Skoda 9000 4 Volvo 29000 5 Bentley 350000 6 Citroen 21000 7 Hummer 41400 8 Volkswagen 21600 We show the contents of the file. mysql> DELETE FROM Cars; mysql> LOAD DATA INFILE '/tmp/cars' INTO TABLE Cars; In the first statement we delete all rows from the table. In the second statement we load all data from the text file into the Cars table. mysql> SELECT * FROM Cars INTO OUTFILE '/tmp/cars.csv' -> FIELDS TERMINATED BY ','; In the above SQL statement, we dump all data from the Cars table into a cars.csv file. The $ cat /tmp/cars.csv 1,Audi,52642 2,Mercedes,57127 3,Skoda,9000 4,Volvo,29000 5,Bentley,350000 6,Citroen,21000 7,Hummer,41400 8,Volkswagen,21600 This is the contents of the cars.csv file. mysql> DELETE FROM Cars; mysql> LOAD DATA INFILE '/tmp/cars.csv' INTO TABLE Cars -> FIELDS TERMINATED BY ','; mysql> SELECT * FROM Cars; +----+------------+--------+ | Id | Name | Cost | +----+------------+--------+ | 1 | Audi | 52642 | | 2 | Mercedes | 57127 | | 3 | Skoda | 9000 | | 4 | Volvo | 29000 | | 5 | Bentley | 350000 | | 6 | Citroen | 21000 | | 7 | Hummer | 41400 | | 8 | Volkswagen | 21600 | +----+------------+--------+ We delete all the data and restore it from the Exporting to XML files It is possible to export and import XML data using the
$ mysql -uroot -p --xml -e 'SELECT * FROM mydb.Cars' > /tmp/cars.xml The $ cat /tmp/cars.xml <?xml version="1.0"?> <resultset statement="SELECT * FROM mydb.Cars " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <row> <field name="Id">1</field> <field name="Name">Audi</field> <field name="Cost">52642</field> </row> <row> <field name="Id">2</field> <field name="Name">Mercedes</field> <field name="Cost">57127</field> </row> <row> <field name="Id">3</field> <field name="Name">Skoda</field> <field name="Cost">9000</field> </row> <row> <field name="Id">4</field> <field name="Name">Volvo</field> <field name="Cost">29000</field> </row> <row> <field name="Id">5</field> <field name="Name">Bentley</field> <field name="Cost">350000</field> </row> <row> <field name="Id">6</field> <field name="Name">Citroen</field> <field name="Cost">21000</field> </row> <row> <field name="Id">7</field> <field name="Name">Hummer</field> <field name="Cost">41400</field> </row> <row> <field name="Id">8</field> <field name="Name">Volkswagen</field> <field name="Cost">21600</field> </row> </resultset> This is the XML file generated by the mysql> TRUNCATE Cars; mysql> LOAD XML /tmp/cars.xml INTO TABLE Cars; We truncate the Cars table. We load data from the XML file. Note that Using mysqldump tool The Dumping table structuresmysqldump -u root -p --no-data mydb > bkp1.sql The above command dumps table structures of all tables in the -- -- Table structure for table `Cars` -- DROP TABLE IF EXISTS `Cars`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Cars` ( `Id` int(11) NOT NULL, `Name` varchar(50) DEFAULT NULL, `Cost` int(11) DEFAULT NULL, PRIMARY KEY (`Id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; Here we see a portion of the Dumping data only$ mysqldump -uroot -p --no-create-info mydb > bkp2.sql This command dumps all data from all tables of the -- -- Dumping data for table `Cars` -- LOCK TABLES `Cars` WRITE; /*!40000 ALTER TABLE `Cars` DISABLE KEYS */; INSERT INTO `Cars` VALUES (1,'Audi',52642),(2,'Mercedes',57127),(3,'Skoda',9000), (4,'Volvo',29000),(5,'Bentley',350000),(6,'Citroen',21000), (7,'Hummer',41400),(8,'Volkswagen',21600); /*!40000 ALTER TABLE `Cars` ENABLE KEYS */; UNLOCK TABLES; Here we can see the data for the Dumping the whole database$ mysqldump -uroot -p mydb > bkp3.sql This command dumps all tables from the Restoring dataWe show, how to restore the database from the backup SQL files. mysql> DROP DATABASE mydb; ERROR 1010 (HY000): Error dropping database (can't rmdir './mydb/', errno: 17) mysql> SHOW TABLES; Empty set (0.00 sec) We drop the $ sudo ls /var/lib/mysql/mydb cars cars.txt $ sudo rm /var/lib/mysql/mydb/cars $ sudo rm /var/lib/mysql/mydb/cars.txt The reason is that (in my case) while doing backups, some of the data were written in the mysql> DROP DATABASE mydb; Query OK, 0 rows affected (0.04 sec) mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | testdb | | world | +--------------------+ 4 rows in set (0.00 sec) The mydb database was fully removed. mysql> CREATE DATABASE mydb; mysql> USE mydb; mysql> source bkp3.sql We create the mysql> SHOW TABLES; +----------------+ | Tables_in_mydb | +----------------+ | AA | | Ages | | Animals | | Authors | | BB | | Books | | Books2 | | Brands | | Cars | ... mysql> SELECT * FROM Cars; +----+------------+--------+ | Id | Name | Cost | +----+------------+--------+ | 1 | Audi | 52642 | | 2 | Mercedes | 57127 | | 3 | Skoda | 9000 | | 4 | Volvo | 29000 | | 5 | Bentley | 350000 | | 6 | Citroen | 21000 | | 7 | Hummer | 41400 | | 8 | Volkswagen | 21600 | +----+------------+--------+ The data is verified. In this part of the MySQL tutorial, we have shown several ways how we can export and import data in MySQL. Contents Previous NextHow do I export an entire MySQL database?Export. Connect to your database using phpMyAdmin.. From the left-side, select your database.. Click the Export tab at the top of the panel.. Select the Custom option.. You can select the file format for your database. ... . Click Select All in the Export box to choose to export all tables.. How do I transfer MySQL database to another computer?You can do by this process step-by-step using MySQL WorkBench.. Install MySQL Workbench.. Connect to existing Database.. Go to Navigator -> Management -> Data Export. ( ... . Create Database on target PC.. Connect to Target Database (would consist of 0 tables in DB). Go to Navigator -> Management -> Data Import/Restore.. What is the command to export MySQL database?sql is the file name. Enter the database password to start MySQL export Database Command Line into the mentioned file. Now connect to the server using FTP and navigate to the directory to download the exported data file. This is how you can perform the MySQL export database command line method.
What is database import and export?Database export and import in MySQL is a process of moving data from one place to another place. Export and import are useful methods for backing up essential data or transferring our data between different versions. For example, we have a contact book database that is essential for our business.
|