Home Database Mysql Tutorial mysql备份数据库以及拷贝数据库到另一台服务器上

mysql备份数据库以及拷贝数据库到另一台服务器上

Jun 07, 2016 pm 03:47 PM
m mysql to use backup copy database server

可以用mysqladmin 创建db,不需要进入后再去创建了。 将mysql数据库导入目标机器后,执行 mysqladminflush-privileges ,以便服务器重载授权表信息。 D:\MySql 5.1.73\bin\mysqladmin -u root create test2; D:\Mysql 5.1.73\bin\mysqladmin -u root drop te

可以用mysqladmin 创建db,不需要进入后再去创建了。

将mysql数据库导入目标机器后,执行mysqladmin flush-privileges,以便服务器重载授权表信息。


D:\MySql 5.1.73\bin\mysqladmin -u root create test2;

D:\Mysql 5.1.73\bin\mysqladmin -u root drop test2; 


warning:

Dropping  the database is potentially a very hard thing to do. 

Any data stored in the database will be destroyed. 

Do you really want to drop the 'test2' database [y/n]


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

你可以在支持相同浮点格式的不同架构之间为MyISAM表复制.frm、.MYI和.MYD文件。(MySQL关注所有字节交换问题)。请参见15.1节,“MyISAM存储引擎”。

如果你需要在不同的架构之间转移数据库,可以使用mysqldump创建含有SQL语句的文件。然后你可以将文件转移到其它机器上,并将它输入到MySQL客户端。

使用mysqldump --help来看有哪些选项可用。如果你正将数据移动到更新版本的MySQL,你应当使用mysqldump –opt来利用各种优化性能来产生更小、可以更快处理的转储文件。

在两台机器之间移动数据库的最简单(尽管不是最快)的方法是在数据库所在的机器上运行下面的命令:

shell> <strong>mysqladmin -h '<em>other_hostname</em>' create <em>db_name</em></strong>
Copy after login
Copy after login
shell> <strong>mysqldump --opt <em>db_name</em> | mysql -h '<em>other_hostname</em>' <em>db_name</em></strong>
Copy after login
Copy after login

如果你想要从远程机器通过慢速网络复制数据库,可以使用:

shell> <strong>mysqladmin create <em>db_name</em></strong>
Copy after login
Copy after login
shell> <strong>mysqldump -h '<em>other_hostname</em>' --opt --compress <em>db_name</em> | mysql <em>db_name</em></strong>
Copy after login

还可以将结果保存到文件中,然后将文件转移到目标机器上并将文件装载到数据库中。例如,可以在源机器上使用下面的命令将数据库备份到文件中:

shell> <strong>mysqldump --quick <em>db_name</em> | gzip > <em>db_name.contents</em>.gz</strong>
Copy after login

(该例子中创建的文件是压缩格式)。将含有数据库内容的文件到目标机上并运行命令:

shell> <strong>mysqladmin create <em>db_name</em></strong>
Copy after login
Copy after login
shell> <strong>gunzip db_name.contents.gz | mysql <em>db_name</em></strong>
Copy after login

还可以使用mysqldumpmysqlimport来转移数据库。对于大的表,比只是使用mysqldump要快得多。在下面的命令中,DUMPDIR代表用来保存mysqldump输出的目录全路径名。

首先,创建保存输出文件的目录并备份数据库:

shell> <strong>mkdir DUMPDIR</strong>
Copy after login
shell><strong>mysqldump --tab=DUMPDIR <em>db_name</em></strong>
Copy after login

然后将DUMPDIR目录中的文件转移到目标机上相应的目录中并将文件装载到MySQL:

shell> <strong>mysqladmin create <em>db_name</em>            # create database</strong>
Copy after login
shell> <strong>cat DUMPDIR/*.sql | mysql <em>db_name</em>    # create tables in database</strong>
Copy after login
shell> <strong>mysqlimport <em>db_name</em> DUMPDIR/*.txt    # load data into tables</strong>
Copy after login

不要忘记复制MySQL数据库,因为授权表保存在该数据库中。你可能需要在新机器上用MySQL root用户运行命令,直到产生MySQL数据库。

将mysql数据库导入目标机器后,执行mysqladmin flush-privileges,以便服务器重载授权表信息。

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

按照上面的方法试了个多小时成功了,主要是上面的命令说的不是很完整:

shell> <strong>mysqladmin -h '<em>other_hostname</em>' create <em>db_name</em></strong>
Copy after login
Copy after login
<strong><em>(mysqladmin -h other_hostname -u username -p create db_name)</em></strong>
Copy after login
shell> <strong>mysqldump --opt <em>db_name</em> | mysql -h '<em>other_hostname</em>' <em>db_name</em></strong>
Copy after login
Copy after login
<strong><em>(</em><strong>mysqldump -h local_host -u username -p local_<em>db_name</em> | mysql -h <em>other_hostname -u username -p db_name</em></strong><em>)</em></strong>
Copy after login

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The relationship between mysql user and database The relationship between mysql user and database Apr 08, 2025 pm 07:15 PM

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL: The Ease of Data Management for Beginners MySQL: The Ease of Data Management for Beginners Apr 09, 2025 am 12:07 AM

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

Can I retrieve the database password in Navicat? Can I retrieve the database password in Navicat? Apr 08, 2025 pm 09:51 PM

Navicat itself does not store the database password, and can only retrieve the encrypted password. Solution: 1. Check the password manager; 2. Check Navicat's "Remember Password" function; 3. Reset the database password; 4. Contact the database administrator.

How to create navicat premium How to create navicat premium Apr 09, 2025 am 07:09 AM

Create a database using Navicat Premium: Connect to the database server and enter the connection parameters. Right-click on the server and select Create Database. Enter the name of the new database and the specified character set and collation. Connect to the new database and create the table in the Object Browser. Right-click on the table and select Insert Data to insert the data.

How to copy tables in mysql How to copy tables in mysql Apr 08, 2025 pm 07:24 PM

Copying a table in MySQL requires creating new tables, inserting data, setting foreign keys, copying indexes, triggers, stored procedures, and functions. The specific steps include: creating a new table with the same structure. Insert data from the original table into a new table. Set the same foreign key constraint (if the original table has one). Create the same index. Create the same trigger (if the original table has one). Create the same stored procedure or function (if the original table is used).

How to view database password in Navicat for MariaDB? How to view database password in Navicat for MariaDB? Apr 08, 2025 pm 09:18 PM

Navicat for MariaDB cannot view the database password directly because the password is stored in encrypted form. To ensure the database security, there are three ways to reset your password: reset your password through Navicat and set a complex password. View the configuration file (not recommended, high risk). Use system command line tools (not recommended, you need to be proficient in command line tools).

How to view mysql How to view mysql Apr 08, 2025 pm 07:21 PM

View the MySQL database with the following command: Connect to the server: mysql -u Username -p Password Run SHOW DATABASES; Command to get all existing databases Select database: USE database name; View table: SHOW TABLES; View table structure: DESCRIBE table name; View data: SELECT * FROM table name;

How to copy and paste mysql How to copy and paste mysql Apr 08, 2025 pm 07:18 PM

Copy and paste in MySQL includes the following steps: select the data, copy with Ctrl C (Windows) or Cmd C (Mac); right-click at the target location, select Paste or use Ctrl V (Windows) or Cmd V (Mac); the copied data is inserted into the target location, or replace existing data (depending on whether the data already exists at the target location).

See all articles