他可以直接用mysql_workbench 6以上的版本直接导入文件夹的方式来导入多个sql文件. 但是在我的服务器上不可能为了批量导这个sql单
因为项目协同开发, 同事发了一个项目的sql文件过来, 打开一看是个目录, 里面有上百个数据库.每个数据库作为一个单独的文件.
每个sql文件里面都有
CREATE DATABASE IF NOT EXISTS `XXXX`
USE `XXXX`;
他可以直接用mysql_workbench 6以上的版本直接导入文件夹的方式来导入多个sql文件. 但是在我的服务器上不可能为了批量导这个sql单独装个GUI的workbench.
于是写个shell吧, 改里面的host,username和password为你对应的即可.
dbname这里,默认是sample, mysql里面的sample表. 实际数据不是导入到这里面的, 因为我要导入的sql文件里面都已经有了创建db. 如果你是要导入到某一个数据库的多个表, 可以修改dbname为你对应的数据库名
#!/bin/bash
#author rainysia
#date 2014-11-14 10:26:27
set -e
LC_ALL=C
LANG=C
unset TZ
TZBase=$(LC_ALL=C TZ=UTC0 date -R)
UTdate=$(LC_ALL=C TZ=UTC0 date -d "$TZBase")
TZdate=$(unset TZ ; LANG=C date -d "$TZBase")
file_path="/home/db/test/" #要导入的sql文件夹
host="192.168.85.123" #要导入的mysql主机
username="dbroot" #mysql的用户名
password="db1t#2w$3r@4#t" #mysql的密码
dbname="sample" #mysql的数据库名
now=$(date "+%s") #计时
mysql_source(){
for file_name in `ls -A $1`
do
seg_start_time=$(date "+%s")
if [ -f "$1$file_name" ];then
command="source $1$file_name"
mysql -h${host} -u${username} -p${password} ${dbname} -e "$command"
echo "source:" \"$1$file_name\" "is ok, It takes " `expr $(date "+%s") - ${seg_start_time}` " seconds"
fi
done
echo "All sql is done! Total cost: " `expr $(date "+%s") - ${now}` " seconds"
}
echo "Universal Time is now: $UTdate."
echo "Local time is now: $TZdate."
mysql_source $file_path
测试一下,
root@debian:/home/sh# ./mysql_source.sh
Universal Time is now: Fri Nov 14 03:10:49 UTC 2014.
Local time is now: Fri Nov 14 11:10:49 CST 2014.
source: "/home/db/test/hml2.sql" is ok, It takes 18 seconds
source: "/home/db/test/hml3.sql" is ok, It takes 19 seconds
source: "/home/db/test/hml4.sql" is ok, It takes 18 seconds
All sql is done! Total costs: 55 seconds
接着发现可以导入了, 然后同事又需要重装某个app, 需要删除其中某个数据库下的所有表. 因为她权限不够, 不能够直接删除数据库, 只能一个一个手动drop table. 但是有2000多个table.
本来打算使用
SELECT CONCAT('DROP TABLE IF EXISTS ', table_name, ';') FROM information_schema.tables WHERE table_schema='cs_china_111数据库名';
的方式来删除所有table, 发现没有生效.
于是还是还是使用上面的shell. 把路径随便换个, 现在先去把需要drop的table的sql给写出来.
先去导出这个数据库,在终端下使用mysqldump dbroot是我的数据库用户名, cs_china_1111是我要导出的数据库, -d -add-drop-table 是不导出数据只导出结构
#mysqldump -udbroot -p cs_china_1111 -d --add-drop-table > cs_china_1111.sql
然后使用grep来过滤一次, 因为导出的sql里面含有了drop table
#find ./ -name "cs_china_1111.sql" | xargs grep "DROP TABLE IF" > cs_china_1111_drop_table.sql
接下来用之前的shell, 把dbname 改成需要删除的数据库名, 运行一下即可.
--------------------------------------分割线 --------------------------------------
Ubuntu 14.04下安装MySQL
《MySQL权威指南(原书第2版)》清晰中文扫描版 PDF
Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL
Ubuntu 14.04下搭建MySQL主从服务器
Ubuntu 12.04 LTS 构建高可用分布式 MySQL 集群
Ubuntu 12.04下源代码安装MySQL5.6以及Python-MySQLdb
MySQL-5.5.38通用二进制安装
--------------------------------------分割线 --------------------------------------
本文永久更新链接地址:
,
mysqlviewshavelimitations:1)他们不使用Supportallsqloperations,限制DatamanipulationThroughViewSwithJoinSorsubqueries.2)他们canimpactperformance,尤其是withcomplexcomplexclexeriesorlargedatasets.3)

porthusermanagementInmysqliscialforenhancingsEcurityAndsingsmenting效率databaseoperation.1)usecReateusertoAddusers,指定connectionsourcewith@'localhost'or@'%'。

mysqldoes notimposeahardlimitontriggers,butacticalfactorsdeterminetheireffactective:1)serverConfiguration impactactStriggerGermanagement; 2)复杂的TriggerSincreaseSySystemsystem load; 3)largertablesslowtriggerperfermance; 4)highConconcConcrencerCancancancancanceTigrignecentign; 5); 5)

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

通过PHP网页界面添加MySQL用户可以使用MySQLi扩展。步骤如下:1.连接MySQL数据库,使用MySQLi扩展。2.创建用户,使用CREATEUSER语句,并使用PASSWORD()函数加密密码。3.防止SQL注入,使用mysqli_real_escape_string()函数处理用户输入。4.为新用户分配权限,使用GRANT语句。

mysql'sblobissuitableForStoringBinaryDataWithInareLationalDatabase,而alenosqloptionslikemongodb,redis和calablesolutionsoluntionsoluntionsoluntionsolundortionsolunsolunsstructureddata.blobobobsimplobissimplobisslowderperformandperformanceperformancewithlararengelitiate;

toaddauserinmysql,使用:createUser'username'@'host'Indessify'password'; there'showtodoitsecurely:1)choosethehostcarecarefullytocon trolaccess.2)setResourcelimitswithoptionslikemax_queries_per_hour.3)usestrong,iniquepasswords.4)Enforcessl/tlsconnectionswith

toAvoidCommonMistakeswithStringDatatatPesInMysQl,CloseStringTypenuances,chosethirtightType,andManageEngencodingAndCollationsEttingsefectery.1)usecharforfixed lengengters lengengtings,varchar forbariaible lengength,varchariable length,andtext/blobforlabforlargerdata.2 seterters seterters seterters seterters


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

禅工作室 13.0.1
功能强大的PHP集成开发环境

SublimeText3 Linux新版
SublimeText3 Linux最新版

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中