我有一个相当大的数据库,所以我想用命令提示符导出它,但我不知道如何。

我正在使用WAMP。


当前回答

mysql -u -p databaseName>fileToPutDatabase . mysql

其他回答

我试图转储在docker上运行的db,并提出了以下命令来实现相同的目的:

Docker exec <container_id/name> /usr/bin/mysqldump -u <db_username>——password=<db_password> db_name > .sql

希望这能有所帮助!

您可以使用此脚本从终端导出或导入任何数据库 网址: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 --no-tablespaces -u username -p pass database_name > db_backup_file.sql

找到你的mysql实例:

which mysql

如果这是正确的,然后用以下方法导出(否则导航到bin中的mamp文件夹中的mysql实例):

mysqldump -u [username] -p [password] [dbname] > filename.sql

如果你想在同一时间压缩它:

mysqldump -u [username] -p [password] [db] | gzip > filename.sql.gz

然后你可以在服务器之间移动这个文件:

scp user@xxx.xxx.xxx.xxx:/path_to_your_dump/filename.sql.gz your_detination_path/

(其中xxx.xxx.xxx.xxx为服务器IP地址)

然后导入:

gunzip filename.sql.gz | mysql -u [user] -p [password] [database]

mysql -u -p databaseName>fileToPutDatabase . mysql