您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这期内容当中小编将会给大家带来有关使用shell脚本怎么删除mysql中的重复数据,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
#!/bin/sh # delete all company's duplicate uid MYSQL_BIN_PATH=/data/mysql/server/mysql_3306/bin MYSQL_SOCK_PATH=/data/mysql/server/mysql_3306/tmp DBUSER=dbuser DBPWD=userpwd DBHOSTNAME=192.168.1.105 PORT=3306 # get all company_id for company_id in `${MYSQL_BIN_PATH}/mysql -u${DBUSER} -p${DBPWD} -h ${DBHOSTNAME} -P ${PORT} --socket=${MYSQL_SOCK_PATH}/mysql.sock -e " SELECT company_id FROM company.companypage;"` do if [ $company_id != "company_id" ] ; then # if [ $company_id -eq 2733 ] ; then suffix=`expr ${company_id} % 100` for user_id in `${MYSQL_BIN_PATH}/mysql -u${DBUSER} -p${DBPWD} -h ${DBHOSTNAME} -P ${PORT} --socket=${MYSQL_SOCK_PATH}/mysql.sock -e " SELECT user_id FROM company.company_candidate_${suffix} WHERE company_id=${company_id} AND user_id>0 GROUP BY company_id, user_id HAVING COUNT(user_id) > 1;"` do if [ $user_id != "user_id" ] ; then ${MYSQL_BIN_PATH}/mysql -u${DBUSER} -p${DBPWD} -h ${DBHOSTNAME} -P ${PORT} --socket=${MYSQL_SOCK_PATH}/mysql.sock -e " DELETE FROM company.company_candidate_${suffix} WHERE company_id=${company_id} and user_id=${user_id} limit 1;" echo "delete from company_candidate_${suffix} where company_id=${company_id} and user_id=${user_id} limit 1" fi done # fi fi done exit 0
上述就是小编为大家分享的使用shell脚本怎么删除mysql中的重复数据了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。