Need help on this.
I would like to make my general_log file for mysql from single huge file into a daily log file.
I created a batch file to rename and create anew general log file,
but it still write into the renamed file.
Are there a config in mysql or am I missing a command here, so that the general log will not write on the renamed file / or just create a new general log / or will just write to the new empty file? thanks in advance
btw, batch file is below:
#echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set
dt=%%a
set YYYY=%dt:~0,4%
set MM=%dt:~4,2%
set DD=%dt:~6,2%
set HH=%dt:~8,2%
set Min=%dt:~10,2%
set Sec=%dt:~12,2%
set stamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%
ren C:\wamp\logs\generalmysql.log "generalmysql - %stamp%.log"
#echo off
echo.>"C:\wamp\logs\generalmysql.log"
Screenshot
solved my issue by flushing the logs
call "C:\wamp\bin\mysql\mysql5.7.14\bin\mysqladmin.exe" -u'root' -h localhost flush-logs
Related
I am trying to write a batch file to force Google Chrome to Update. If I use the following it is close however the batch file below takes out the : and shows a This Site Can't Be Reached notification:
#echo on
start chrome.exe \chrome://chrome
pause
If I had a batch file to open chrome:chrome in a startup page that would be helpful as well.
You could use the profile manager and create a user/profile with chrome://chrome as the start page. Or manually/per batch create a copy of the preferences file in "%USERPROFILE%\AppData\Local\Google\Chrome\User Data\Default" and switch between two versions of the file.
The following batch will just create a backup with datetime appended to the name to start with.
#Echo off
:: GetISODT
for /f "tokens=1-3 delims=.+-" %%A in (
'wmic os get LocalDateTime^|findstr ^^[0-9]'
) do Set _DT=%%A
Pushd "%USERPROFILE%\AppData\Local\Google\Chrome\User Data\Default"
copy Preferences Preferences_%_DT%
start chrome
We can find mdf and ldf file locations either by using sp_helpdb or using the below command.
SELECT * FROM sys.master_files
But how can we find ldf and mdf files which are not being used at present i.e Let say you restored one database with new mdf and ldf files and not deleted old mdf and ldf files .
There isn't a straight forward easy way. You can manually do this by searching the server or there is a more complex way spelled out here:
Finding un-used data files
You can try the below way:
IF OBJECT_ID(N'tempdb.dbo.#AllMDFfiles', N'U') IS NOT NULL
BEGIN DROP TABLE #AllMDFfiles END
CREATE TABLE #AllMDFfiles (mdfFileName VARCHAR(max))
-- Will return all the .mdf and .ldf in C:\ drive, you can change it in ... /d C:\ && dir /b....
INSERT INTO #AllMDFfiles EXEC xp_cmdshell 'cmd /c "cd /d C:\ && dir /b /s | sort | findstr /c:".mdf" /c:".ldf""'
--Will return the mdfs and ldf paths which are not in sys.master_files
select mdfFileName from #AllMDFfiles
Where mdfFileName IS NOT NULL
EXCEPT
SELECT physical_name FROM sys.master_files
I use the following .bat script
set varSearch="C:\Users\User1\Desktop\Test-folder\*.crypt8"
for /f %%i in ('dir %varSearch% /B ') do set varSearch= %%i
WhatsAppViewer.exe -decrypt8 %myName% key exp.db
sqlite3.exe exp.db<command.txt
cd C:\xampp\mysql\bin
mysql -u admin -p1234 < query.txt
The basic function is to find a file thats ending with .crypt8, decrypt it, save as csv and import to mysql. Its working correctly
But i need some extra features
Case1
The folder contains more than 1 file, and every file has to be processed, but only once
Case 2
Everyday at least one file gets added. It would be superb if the .bat could be scheduled as a task, and run every night and just process the new added files.
Does anybody has a solution for this?
Case 2
The forfiles command processes groups of files based on date. This does files made today only.
forfiles /d 0 /m *.crypt8 /c "cmd /c echo #fname in #path"
Case 1
Your code has errors, it may work but not under all conditions.
The easist way is to put the sequence of commands in a batchfile for a file (%1) which is passed on command line, and use forfiles to call it.
I'm using the following code to delete all instances of Acad.lsp found on my C:\ drive but I want to make one exception, which is C:\Autocad 2010\Support.
How can I achieve this?
del "C:\ICT\acad.lsp" /q /a /s
From a command line you could use the batch file for command (I'm assuming that you're using a Windows command prompt or similar here). This is a powerful command that will let you loop through a set of "things" - with the right options, these "things" may be files.
The following command, when run in the C:\ICT directory, should do what you want:
for /F "usebackq" %a in (`dir /s /b acad.lsp ^| find /v "C:\Autocad 2010\Support"`) do #echo %a
Note that I'm using #echo here so that you can test that the results are as you expect before you change the #echo to del.
If you wanted to put this into a batch file, you should change %a to %%a.
A little explanation on what's happening:
for /F "usebackq" %a in (...) runs the command that is between the back-quotes, and runs the command following the do on each item that results. The command in my example above does a recursive dir for the file acad.lsp, and puts that through the find command to remove the one you want to keep. The remaining files are the ones that you will want to delete.
I have the following file dumped daily into one of our online directories:
dat-part2-489359-43535-toward.txt
The numbers change each day randomly.
I have the following code to try and LOAD the file:
mysql_query("LOAD DATA LOCAL INFILE 'dat-part2-%-toward.txt'
REPLACE INTO TABLE my_table
FIELDS TERMINATED BY ',' ENCLOSED BY ''
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES") or die(mysql_error());
And of course no luck. What's the best way to do this?
assuming this is a scheduled job, why not check the directory for the most recent file that matches your filename template. Store the name of said file in a variable and then sub the variable into your query. Check out glob()
I would do it via a shell script or windows cmd file. This assumes you created the file with mysqldump or some program that creates a valid sql script.
You can run dir /B in windows commend to get a directory of files. So do a dir /B > input.txt then use Windows scripting to read the input file and for each line, pipe the file in using the mysql client.
# echo off set infile= %%1
for /f "eol= tokens=*
delims= usebackq" %%i in (%infile%)
do ( mysql -u userName --password=pwd < %%i )
It's been a long time since I wrote any windows scripts, but that should give you an idea of an approach.