要导出数据库,请使用以下命令:
mysqldump -u username -p databasename > filename.sql
请注意每种情况下的符号。
尝试
mysqldump databaseExample > file.sql
如果您已经在运行SQL shell,则可以使用source命令导入数据:
use databasename; source data.sql;
mysqldump不会转储数据库事件,触发器和例程,除非在转储个别数据库时明确指出;
mysqldump -uuser -p db_name --events --triggers --routines > db_name.sql
将整个数据库转储到文件中:
mysqldump -u USERNAME -p password DATABASENAME > FILENAME.sql
那么你可以使用下面的命令导出,
mysqldump –database –user = root –password your_db_name> export_into_db.sql
并且生成的文件将在您运行此命令的同一目录中可用。
现在用命令login到mysql,
mysql -u [用户名] -p
然后在文件path中使用“source”命令。
你可以find更多的: 导入导出MySQL数据库
请享用 :)
您可以使用此脚本导出或导入从此链接提供的任何数据库: 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 &#39;Would like you like to change the default location [y/n]: &#39; location_change read -p "Please enter your username: " u_name read -p &#39;Would you like to import or export a database: [import/export]: &#39; action echo mysqldump_location&#61;/opt/lampp/bin/mysqldump mysql_location&#61;/opt/lampp/bin/mysql if [ "$action" &#61;&#61; "export" ]; then if [ "$location_change" &#61;&#61; "y" ]; then read -p &#39;Give the location of mysqldump that you want to use: &#39; mysqldump_location echo else echo -e "Using default location of mysqldump\n" fi read -p &#39;Give the name of database in which you would like to export: &#39; db_name read -p &#39;Give the complete path of the .sql file in which you would like to export the database: &#39; sql_file $mysqldump_location -u $u_name -p $db_name > $sql_file elif [ "$action" &#61;&#61; "import" ]; then if [ "$location_change" &#61;&#61; "y" ]; then read -p &#39;Give the location of mysql that you want to use: &#39; mysql_location echo else echo -e "Using default location of mysql\n" fi read -p &#39;Give the complete path of the .sql file you would like to import: &#39; sql_file read -p &#39;Give the name of database in which to import this file: &#39; db_name $mysql_location -u $u_name -p $db_name <$sql_file else echo "please select a valid command" fi
因为我没有足够的声望来评论最高职位&#xff0c;所以我在这里添加。
使用&#39;|&#39; 在linux平台上节省磁盘空间。
thx &#64;Hariboo&#xff0c;添加事件/触发器/路由参数
mysqldump -x -u [uname] -p[pass] -C --databases db_name --events --triggers --routines | sed -e &#39;s/DEFINER[ ]*&#61;[ ]*[^*]*\*/\*/ &#39; | awk &#39;{ if (index($0,"GTID_PURGED")) { getline; while (length($0) > 0) { getline; } } else { print $0 } }&#39; | grep -iv &#39;set &#64;&#64;&#39; | trickle -u 10240 mysql -u username -p -h localhost DATA-BASE-NAME
一些问题/提示&#xff1a;
错误&#xff1a;……在使用LOCK TABLES时不存在
# --lock-all-tables&#xff0c;-x , this parameter is to keep data consistency because some transaction may still be working like schedule. # also you need check and confirm: grant all privileges on *.* to root&#64;"%" identified by "Passwd";
错误2006(HY000)在866行&#xff1a;MySQL服务器已经消失mysqldump&#xff1a;写到errno 32
# set this values big enough on destination mysql server, like: max_allowed_packet&#61;1024*1024*20 # use compress parameter &#39;-C&#39; # use trickle to limit network bandwidth while write data to destination server
错误1419(HY000)在行32730&#xff1a;您没有SUPER权限和启用二进制日志logging(您可能希望使用不太安全的log_bin_trust_function_creatorsvariables)
# set SET GLOBAL log_bin_trust_function_creators &#61; 1; # or use super user import data
错误1227(42000)在行138&#xff1a;访问被拒绝; 你需要(至less有一个)SUPER权限(s)用于这个操作mysqldump&#xff1a;在写入时得到errno 32
# add sed/awk to avoid some privilege issues
希望这个帮助&#xff01;