我有一个相当大的数据库,所以我想用命令提示符导出它,但我不知道如何。
我正在使用WAMP。
我有一个相当大的数据库,所以我想用命令提示符导出它,但我不知道如何。
我正在使用WAMP。
当前回答
要导出过程、函数和触发器,添加——routines参数:
mysqldump -u yoru -p你的数据库-routines > wantedsqlfile.sql
其他回答
只需使用下面的命令,
出口:
mysqldump -u [user] -p [db_name] | gzip > [filename_to_compress.sql.gz]
进口:
gunzip < [compressed_filename.sql.gz] | mysql -u [user] -p[password] [databasename]
注意:关键字“-p”和密码之间没有空格。
首先检查您的命令行是否识别mysql命令。如果没有,进入命令并输入:
set path=c:\wamp\bin\mysql\mysql5.1.36\bin
然后使用这个命令导出您的数据库:
mysqldump -u YourUser -p YourDatabaseName > wantedsqlfile.sql
然后系统将提示您输入数据库密码。
这将在执行此命令时将数据库导出到您当前所在的路径
注意:这里有一些关于导入和导出的详细说明
我用过wamp服务器。我试了试
c:\wamp\bin\mysql\mysql5.5.8\bin\mysqldump -uroot -p db_name > c:\somefolder\filename.sql
Root是我mysql的用户名,如果你有密码,请指定:
-p[yourpassword]
希望它有用。
您可以使用此脚本从终端导出或导入任何数据库 网址:https://github.com/Ridhwanluthra/mysql_import_export_script/blob/master/mysql_import_export_script.sh
echo -e "Welcome to the import/export database utility\n"
echo -e "the default location of mysqldump file is: /opt/lampp/bin/mysqldump\n"
echo -e "the default location of mysql file is: /opt/lampp/bin/mysql\n"
read -p 'Would like you like to change the default location [y/n]: ' location_change
read -p "Please enter your username: " u_name
read -p 'Would you like to import or export a database: [import/export]: ' action
echo
mysqldump_location=/opt/lampp/bin/mysqldump
mysql_location=/opt/lampp/bin/mysql
if [ "$action" == "export" ]; then
if [ "$location_change" == "y" ]; then
read -p 'Give the location of mysqldump that you want to use: ' mysqldump_location
echo
else
echo -e "Using default location of mysqldump\n"
fi
read -p 'Give the name of database in which you would like to export: ' db_name
read -p 'Give the complete path of the .sql file in which you would like to export the database: ' sql_file
$mysqldump_location -u $u_name -p $db_name > $sql_file
elif [ "$action" == "import" ]; then
if [ "$location_change" == "y" ]; then
read -p 'Give the location of mysql that you want to use: ' mysql_location
echo
else
echo -e "Using default location of mysql\n"
fi
read -p 'Give the complete path of the .sql file you would like to import: ' sql_file
read -p 'Give the name of database in which to import this file: ' db_name
$mysql_location -u $u_name -p $db_name < $sql_file
else
echo "please select a valid command"
fi
你可以使用下面的命令,
Mysqldump——databases——user=root——password your_db_name > export_into_db.sql
生成的文件将在运行此命令的同一目录中可用。
你可以找到更多关于mysqldump的官方参考:Import Export MySQL DB
注意:使用——databases代替——database,因为不再支持最后一个。
享受:)