mysql数据库中查询一个字段相同,另一个字段不相同的数据的数据
如查询所有跨律所的律师数据:SELECT DISTINCT x.lawyer_id,x.lawfirm_id FROM
answer as x,
answer as y WHERE x.id<1000 and x.lawyer_id=y.lawyer_id and x.lawfirm_id!=y.lawfirm_id
注:性能有限,大数据量不建议使用
如查询所有跨律所的律师数据:SELECT DISTINCT x.lawyer_id,x.lawfirm_id FROM
answer as x,
answer as y WHERE x.id<1000 and x.lawyer_id=y.lawyer_id and x.lawfirm_id!=y.lawfirm_id
注:性能有限,大数据量不建议使用
windows下备份mysql数据库脚本,可添加到计划任务中实现定时自动备份。默认存储位置为d:\backup(注:为避免中文乱码,请使用ANSI保存)
@echo off
:begin
rem 接收信息
set input=
set /p input=请输入数据库名称:
if "%input%" == "" (
goto begin
)
echo "正在备份 %input%"
set yyyy=%date:~,4%
set mm=%date:~5,2%
set dd=%date:~8,2%
if /i %time:~0,2% lss 10 set hh=0%time:~1,1%
if /i %time:~0,2% geq 10 set hh=%time:~0,2%
set mn=%time:~3,2%
set ss=%time:~6,2%
set date=%yyyy%%mm%%dd%
set time=%hh%%mn%%ss%
set filename=%date%_%time%
::设置备份目录
set label=d:\
set backDir=backup\
set pwd=123456
if exist %label%%backDir% (
::echo 目录%label%%backDir%已存在,无需创建
) else (
echo 创建%label%%backDir%
md %label%%backDir%
)
::主要为当前正在开发的数据备份,已上线系统优先依据线上系统数据库
"E:\wamp\bin\mysql\mysql5.7.31\bin\mysqldump">mysqldump --opt -P3306 -u root --password=%pwd% --databases %input% --single-transaction >%label%%backDir%%input%_%filename%.sql
:: more...
echo "完成备份 %input%"
goto begin
判断字段是否存在值,如果不存在则写入本行中另一个字段值。update table_name set new_column= case when (new_column=0) then old_column else new_column end
即:如new_column不存在值则更新为old_column
1、修改 /etc/my.cnf
,在 [mysqld] 小节下添加一行:skip-grant-tables=1
2、重启 mysqld 服务:systemctl restart mysqld
3、使用 root 用户登录到 mysql -u root
4、切换到mysql数据库,更新 user 表:update user set authentication_string = password('root'), password_expired = 'N', password_last_changed = now() where user = 'root';
在之前的版本中,密码字段的字段名是 password
,5.7版本改为了 authentication_string
5、退出 mysql,编辑 /etc/my.cnf
文件,删除 skip-grant-tables=1
的内容
6、重启 mysqld 服务,再用新密码登录即可
update gy_user_lawyer as u left join gy_user_lawyer_info as ui on u.ul_id = ui.ul_id set u.ul_tel = ui.uli_remark where u.ul_tel is null;
经常会错误的认为NULL
与空字符串''
是相同的。这看似是一件不重要的事情,但是在MySQL中,这两者是完全不同的。NULL
是指没有值,而''
则表示值是存在的,只不过是个空值。对于SQL的新手,NULL值的概念常常会造成混淆,他们常认为NULL与MySQL空字符串是相同的事。情况并非如此。例如,下述语句是完全不同的:MySQL> INSERT INTO my_table (phone) VALUES (NULL);
mysql> INSERT INTO my_table (phone) VALUES ('');