本问题已经有最佳答案,请猛点这里访问。
我想从命令行向MySQL数据库导出和导入.sql文件。
MySQL中有导出.sql文件的命令吗?那我该如何导入呢?
执行导入时,可能存在诸如启用/禁用外键检查或仅导出表结构之类的约束。
我们可以用mysqldump设置这些选项吗?
mysqldump是一个单独的命令。你不应该在mysql里运行它。只需在命令提示符前编写它。分号表示命令已经结束。由于您在终端上以程序的形式运行mysqldump,因此不应该以分号结束它。
感谢Ozair,所有人都有任何方法可以设置属性,如设置外键、仅结构、仅数据
请参阅stackoverflow.com/questions/17666249/…
已检查mysql选项,但未找到任何仅用于导出结构/数据的方法
@塞缪尔·列为什么这个问题标记为"重复",我在回答上述问题之前问过这个问题,你查过提问日期了吗?
to the following型进出口日期:SQL命令文件P></
$ mysql -u username -p -h localhost DATA-BASE-NAME < data.sql
在这data.sql进出口文件example,博客是为数据库用户名:using Vivek asP></
$ mysql -u vivek -p -h localhost blog < data.sql
如果你有一个dedicated数据库服务器主机名localhost,replace with with actual服务器名称或IP地址和顺序如下:P></
$ mysql -u username -p -h 202.54.1.10 databasename < data.sql
to the following出口到数据库,使用:P></
mysqldump -u username -p databasename > filename.sql
已知的符号在每个>the
如果你already running the SQL外壳,你可以使用Command to the source进出口日期:P></
use databasename;
source data.sql;
导入转储数据的最佳选项。如果已使用mysqldump导出数据,则此导入选项将在几秒钟内生效。
mysqldump will not转储数据库事件触发器和例程,除非当个体explicitly stated倾销数据库;P></
mysqldump -uuser -p db_name --events --triggers --routines > db_name.sql
我不知道为什么这个答案没有赢得很多赞成票。这是唯一一个指向--events的答案。好的,不管怎样,我认为这是很重要的,谢谢你。
这是正确的答案!
的确如此;
这包括起诉吗?
尝试P></
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></
mysqldump -u USERNAME -p password DATABASENAME > FILENAME.sql
如何设置诸如启用/禁用外键检查或使用mysqldump只导出表结构之类的约束
因为我没有足够的声誉after the highest to comment add后,我在这里。P></
使用Linux平台是|在线保存的硬盘空间。P></
谢谢@ hariboo套路的触发器,事件/文件/参数P></
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></
# --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></
# 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></
# 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></
# add sed/awk to avoid some privilege issues
希望这帮助!P></
我遇到了错误1227(42000)。不知道添加sed/awk是什么意思。
你可以使用这个脚本从任何出口或进口到终端数据库链接:given at this HTTPS:/ / / / github.com ridhwanluthra进出口贸易_ _ _ MySQL MySQL /硕士/脚本/ BLOB _ _ _ script.sh进出口贸易P></
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