English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

MySQL-Befehlszeile Exportieren und Importieren Datenbankbeispiel im Detail

MySQL命令行导出数据库:

1,进入MySQL目录下的bin文件夹:cd MySQL中到bin文件夹的目录

如我输入的命令行:cd C:\Program Files\MySQL\MySQL Server 5.5\bin
(或者直接将windows的环境变量path中添加该目录)

 2,导出数据库:mysqldump -u Username -p 数据库名 > 导出的文件名

如我输入的命令行:mysqldump -u lmapp -p lmapp -P 3308 > lmapp.sql   (输入后会让你输入进入MySQL的密码)
(如果导出单张表的话在数据库名后面输入表名即可)

       mysql导出数据库一个表
  mysqldump -u Username -p 数据库名 表名> 导出的文件名
  mysqldump -u lmapp -p lmapp users> test_users.sql (结尾没有分号)

3、会看到文件news.sql自动生成到bin文件下  

 导出时,遇到上面的问题。

解决措施:加个参数-P 3308(mysql服务端口)即可解决问题。

命令行导入数据库:

1,将要导入的.sql文件移至bin文件下,这样的路径比较方便
2,同上面导出的第1步
3,进入MySQL:mysql -u Username -p
如我输入的命令行:mysql -u root -p   (输入同样后会让你输入MySQL的密码)
4,在MySQL-在Front中新建你要建的数据库,这时是空数据库,如新建一个名为news的目标数据库
5,输入:mysql>use 目标数据库名
如我输入的命令行:mysql>use news;
6,导入文件:mysql>source 导入的文件名;

如我输入的命令行:mysql>source news.sql; 

       注意:由于导入数据库的规模、数据结构不同,导入所需时间会有较大差异。我导入的数据库有123M,花费将近5个小时。期间以为机器宕掉了,仔细观察命令行界面发现,导入是在正常进行的。导入成功后的界面如下:

      

      注意:在导入单个数据表时,请使用类似于use lmapp lm_area、source lm_area.sql的SQL语句。原始数据表可以存在,导入后的数据表将覆盖同名已存在的数据表。

      MySQL的备份和还原都是通过mysqldump、mysql和source命令来完成的。

1.Win32.Backup and Restore of MySQL

1.1 Backup

Start Menu | Run | cmd | Use "cd \Program Files\MySQL\MySQL Server 5.0\bin”command to enter the bin folder | Use "mysqldump  -u Username -p databasename >exportfilename”export the database to a file, such as mysqldump -u root -p voice>voice.sql, then input the password to start exporting.

1.2 Restore

Enter the MySQL Command Line Client, input the password, enter "mysql>", input the command "show databases;", enter, see what databases are available; create the database you want to restore, input "create database voice;", enter; switch to the newly created database, input "use voice;", enter; import data, input "source voice.sql;", enter, start importing, when you see "mysql>" again and no error messages are displayed, the restore is successful.

2.Backup and Restore of MySQL under Linux

2.1 Backup

[root@localhost ~]# cd /var/lib/mysql (enter the MySQL library directory, adjust the directory according to your MySQL installation)
[root@localhost mysql]# mysqldump -u root -p voice>voice.sql, enter the password to proceed.

2.2 Restore

Method 1:

[root@localhost ~]# mysql -u root -p Enter, input the password, enter the MySQL console "mysql>", and1.2Restore.

Method 2:

[root@localhost ~]# cd /var/lib/mysql (enter the MySQL library directory, adjust the directory according to your MySQL installation)
[root@localhost mysql]# mysql -u root -p voice<voice.sql, enter the password to proceed.

Thank you for reading, I hope it can help everyone, thank you for your support to this site!

Gefällt mir