How to export and import a .sql file from command line with options?
我想从命令行向MySQL数据库导出和导入.sql文件。
MySQL中有导出.sql文件的命令吗?那我该如何导入呢?
执行导入时,可能存在诸如启用/禁用外键检查或仅导出表结构之类的约束。
我们可以用
to the following型进出口日期:SQL命令文件P></
1 |
在这data.sql进出口文件example,博客是为数据库用户名:using Vivek asP></
1 |
如果你有一个dedicated数据库服务器主机名localhost,replace with with actual服务器名称或IP地址和顺序如下:P></
1 |
to the following出口到数据库,使用:P></
1 | mysqldump -u username -p databasename > filename.sql |
已知的符号在每个
如果你already running the SQL外壳,你可以使用Command to the
mysqldump will not转储数据库事件触发器和例程,除非当个体explicitly stated倾销数据库;P></
1 | mysqldump -uuser -p db_name --events --triggers --routines > db_name.sql |
尝试P></
1 | mysqldump databaseExample > file.sql |
好的,你可以使用以下命令的输出。P></
mysqldump --database --user=root --password your_db_name >
export_into_db.sql
will be available and the generated文件目录中的where the same然你有这个命令。P></
现在登录到MySQL的命令行使用。P></
mysql -u[username] -p
然后使用"源文件"命令与路径。P></
数据库转储到文件:安全部P></
1 |
因为我没有足够的声誉after the highest to comment add后,我在这里。P></
使用Linux平台是|在线保存的硬盘空间。P></
谢谢@ hariboo套路的触发器,事件/文件/参数P></
1 | mysqldump -x -u [uname] -p[pass] -C --databases db_name --events --triggers --routines | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/ ' | awk '{ if (index($0,"GTID_PURGED")) { getline; while (length($0) > 0) { getline; } } else { print $0 } }' | grep -iv 'set @@' | trickle -u 10240 mysql -u username -p -h localhost DATA-BASE-NAME |
提示:一些问题/P></
误差:当使用表锁not exist……P></
1 2 | # --lock-all-tables,-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@"%" identified by"Passwd"; |
误差线(hy000)在2006年离开了有866:MySQL服务器mysqldump在线:有32写入错误P></
1 2 3 | # set this values big enough on destination mysql server, like: max_allowed_packet=1024*1024*20 # use compress parameter '-C' # use trickle to limit network bandwidth while write data to destination server |
1419年(误差在hy000):You do not have 32730在线超级特权和测井is the binary促成(你可能想使用the less _仓安全日志_信托_ _ creators函数变量)P></
1 2 | # set SET GLOBAL log_bin_trust_function_creators = 1; # or use super user import data |
误差(42000 1227):在网络接入denied 138;You need(one of the least)超级特权(S)for this operationmysqldump在线:有32写入错误P></
1 | # add sed/awk to avoid some privilege issues |
希望这帮助!P></
你可以使用这个脚本从任何出口或进口到终端数据库链接:given at this HTTPS:/ / / / github.com ridhwanluthra进出口贸易_ _ _ MySQL MySQL /硕士/脚本/ BLOB _ _ _ script.sh进出口贸易P></
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | echo -e"Welcome to the import/export database utility " echo -e"the default location of mysqldump file is: /opt/lampp/bin/mysqldump " echo -e"the default location of mysql file is: /opt/lampp/bin/mysql " 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 " 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 " 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 |