*Problemă/Întrebare: Cum pot sa sterg automat log din mysql db
Tipologie server: zt2
*Resursă folosită:zt2
*ServerFiles utilizat:
*Syserr:
Poză:
*Detalii suplimentare:
Cum pot sa sterg automat log din mysql db ? Sunt mereu plecat si nu am timp si as dori sa fac cumva sa se stearga automat, gen cum este crontab pentru game
as vrea sa se curete log din mysql nu sa imi stearga tab
Cum pot sa sterg automat log din mysql db Problemă rezolvată
Ii faci un cronjob la scriptu asta si aia e
https://www.cloudways.com/blog/schedule ... bs-in-php/
<?php
// MySQL database connection
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// SQL query to truncate table
$sql = "TRUNCATE TABLE your_table_name";
// Execute query
if ($conn->query($sql) === TRUE) {
echo "Table cleared successfully";
} else {
echo "Error clearing table: " . $conn->error;
}
// Close connection
$conn->close();
?>
https://www.cloudways.com/blog/schedule ... bs-in-php/
<?php
// MySQL database connection
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// SQL query to truncate table
$sql = "TRUNCATE TABLE your_table_name";
// Execute query
if ($conn->query($sql) === TRUE) {
echo "Table cleared successfully";
} else {
echo "Error clearing table: " . $conn->error;
}
// Close connection
$conn->close();
?>
Sau daca te referi la log din ftp poti face un sh cu codul de mai jos si ii faci un crontab.
#!/bin/bash
# Check if both file and path are provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <file_name> <path>"
exit 1
fi
file_name=$1
path=$2
# Check if the file exists in the specified path
if [ ! -f "$path/$file_name" ]; then
echo "File '$file_name' not found in path '$path'"
exit 1
fi
# Delete the file
rm "$path/$file_name"
echo "File '$file_name' deleted successfully from path '$path'"
Comanda
./delete_file.sh example.txt /path/to/directory
#!/bin/bash
# Check if both file and path are provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <file_name> <path>"
exit 1
fi
file_name=$1
path=$2
# Check if the file exists in the specified path
if [ ! -f "$path/$file_name" ]; then
echo "File '$file_name' not found in path '$path'"
exit 1
fi
# Delete the file
rm "$path/$file_name"
echo "File '$file_name' deleted successfully from path '$path'"
Comanda
./delete_file.sh example.txt /path/to/directory
-
- Informaţie
-
Cine este conectat
Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 3 vizitatori

