Lamp build 24:mysql Backup and restore

Source: Internet
Author: User

Use the Mysqldump tool to back up Discuz database to/data/discuz.sql as root user, password aming.com

[Email protected] mysql]# mkdir-p/data/bak/mysql/

[Email protected] mysql]# mysqldump-uroot-p123456 discuz >/data/bak/mysql/discuz.sql

View the contents of a backup

[Email protected] mysql]# Head/data/bak/mysql/discuz.sql

--MySQL dump 10.13 distrib 5.1.49, for Pc-linux-gnu (i686)

--

--Host:localhost Database:discuz

-- ------------------------------------------------------

--Server version 5.1.49

/*!40101 SET @[email protected] @CHARACTER_SET_CLIENT */;

/*!40101 SET @[email protected] @CHARACTER_SET_RESULTS */;

/*!40101 SET @[email protected] @COLLATION_CONNECTION */;

/*!40101 SET NAMES UTF8 */;

......

Backup is done by creating a library, creating tables, inserting data into the law, so you can recover. If we accidentally deleted the database of the forum, our forum could not be used.

mysql> drop Database Discuz;

Query OK, 297 rows affected (0.04 sec)

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M00/8C/DF/wKioL1h8hs7TQHvQAAFkeg80zzk710.png-wh_500x0-wm_ 3-wmp_4-s_3427367125.png "title=" 1.png "alt=" Wkiol1h8hs7tqhvqaafkeg80zzk710.png-wh_50 "/>

Once the database is restored, the forum can be used again.

mysql> CREATE DATABASE Discuz;

Query OK, 1 row Affected (0.00 sec)

[Email protected] discuz]# mysql-uroot-p123456 Discuz </data/bak/mysql/discuz.sql

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M00/8C/E3/wKiom1h8hufz10RnAAE0SiwAJGQ068.png-wh_500x0-wm_ 3-wmp_4-s_1728712059.png "title=" 2.png "alt=" Wkiom1h8hufz10rnaae0siwajgq068.png-wh_50 "/>

To back up a table, you need to add a table name

[[email protected] discuz]# mysqldump-uroot-p123456 mysql user >/data/bak/mysql/user.sql

Restore a table without adding a table name

[Email protected] discuz]# mysql-uroot-p123456 MySQL </data/bak/mysql/user.sql

To avoid inconsistent backup and restore character sets, we can specify character set backup and restore

[[email protected] discuz]# mysqldump-uroot-p123456--default-character-set=gbk mysql user >/data/bak/mysql/ User.sql

[[email protected] discuz]# mysql-uroot-p123456--DEFAULT-CHARACTER-SET=GBK MySQL </data/bak/mysql/user.sql


Lamp build 24:mysql Backup and restore

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.