This guide provides step-by-step instructions for setting up the database to store GPS coordinates and timestamps of drone detections.
- Operating System: Ubuntu 22.04 or similar
- Database Software: MySQL Server
- Python: Installed with required libraries (if using scripts)
-
Update the System:
sudo apt update sudo apt upgrade
-
Install MySQL Server:
sudo apt install mysql-server
-
Start MySQL Service:
sudo systemctl start mysql.service
-
Check MySQL Service Status:
sudo service mysql status
-
Log into MySQL:
sudo mysql
-
Reset MySQL Root Password:
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'your_password';
-
Log Back In with New Password:
mysql -u root -p
-
Create Database:
CREATE DATABASE GPS;
-
Use the Database:
USE GPS;
-
Define the Table Structure:
CREATE TABLE GPS ( id INT AUTO_INCREMENT PRIMARY KEY, latitude DECIMAL(10, 8), longitude DECIMAL(11, 8), timestamp DATETIME DEFAULT CURRENT_TIMESTAMP );
-
Verify the Table:
SHOW TABLES;
-
Describe Table to Confirm Structure:
DESCRIBE GPS;
-
Insert Data:
INSERT INTO GPS (latitude, longitude) VALUES (8.5931, 76.8938);
-
View Data:
SELECT * FROM GPS;
-
Install MySQL Connector:
pip install mysql-connector-python
-
Sample Python Script to Insert Data:
import mysql.connector # Establish Connection conn = mysql.connector.connect( host="localhost", user="root", password="your_password", database="GPS" ) cursor = conn.cursor() # Insert Data query = "INSERT INTO Coordinates (latitude, longitude) VALUES (%s, %s)" data = (8.5613, 76.8767) cursor.execute(query, data) conn.commit() print("Data Inserted Successfully") # Close Connection conn.close()
-
Export Database to a File:
mysqldump -u root -p GPS > gps_backup.sql
-
Restore Database from a File:
mysql -u root -p GPS < gps_backup.sql
- Ensure proper privileges are set for remote connections if required.
- Use secure passwords and follow best practices for database security.