Python program to implement N Queens problem

Python program to implement N Queens problem:   def isSafe(board, row, col, n): # check if there is a queen in the same row for i in range(col): if board[row][i] == 1: return False # check if there is a queen in the upper diagonal on the left side for i, j in zip(range(row, -1, … Read more

Upgrade MySQL 5.7 to 8 via Shell script

Here we will write a Shell script to upgrade MySQL 5.7 to 8. #!/bin/bash # Stop MySQL 5.7 server sudo systemctl stop mysql # Backup MySQL 5.7 data sudo mkdir /var/lib/mysql_backup sudo cp -R /var/lib/mysql/* /var/lib/mysql_backup # Remove MySQL 5.7 sudo apt-get remove mysql-server mysql-client mysql-common # Add MySQL 8.0 repository sudo wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.13-1_all.deb … Read more

Monitor MySQL Error logs from AWS Cloudwatch

Here we will write a Python script that will Monitor MySQL Error logs from AWS Cloudwatch and we’ll notify in case any error is detected. import boto3 import gzip import re import smtplib import os from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart # AWS credentials aws_access_key_id = ‘YOUR_ACCESS_KEY_ID’ aws_secret_access_key = ‘YOUR_SECRET_ACCESS_KEY’ # CloudWatch log … Read more

Python program to monitor disk usage in EC2

Here we will write a Python program to monitor disk usage in AWS EC2 instance, you can use this to on any Linux flavor. import os def get_disk_usage(): total, used, free = os.popen(“df -h /”).readlines()[1].split()[1:4] return { “total”: total, “used”: used, “free”: free } if __name__ == “__main__”: usage = get_disk_usage() print(“Disk usage:”) print(f”Total: {usage[‘total’]}”) … Read more

MySQL Shell/Bash script for backup using Mysqldump

Here we will write a Shell/Bash script for taking MySQL backup using Mysqldump command. You can schedule this in cron for daily backups. #!/bin/bash # MySQL database credentials user=”your_username” password=”your_password” host=”localhost” db_name=”your_database_name” # Other options backup_path=”/path/to/backup/directory” date=$(date +”%d-%b-%Y”) # Backup filename backup_file=”$backup_path/$db_name-$date.sql” # Dump the MySQL database mysqldump –user=$user –password=$password –host=$host $db_name > $backup_file # … Read more

MySQL Error: 1142, SELECT command denied to user

So I went through the error while migrating one of the app to cloud. The full error statement goes like : MySQL Error: #1142. Response form the database. SELECT command denied to user “username@ip” for table “table1” From the error statement it looks like that ‘SELECT’ access is missing for the user for that particular … Read more