
Intro in MySql
MySQL is a popular open-source relational database management system (RDBMS) that is widely used for storing, managing, and retrieving data. It's known for its reliability, scalability, and ease of use. Since you're already familiar with PostgreSQL and MySQLi, you might find MySQL concepts easy to grasp.
🔎 Key Features of MySQL
- Relational Database: Data is stored in tables with rows and columns, supporting relationships using primary and foreign keys.
- SQL Support: MySQL uses Structured Query Language (SQL) to perform database operations like
SELECT
,INSERT
,UPDATE
, andDELETE
. - Scalability: Can handle large databases and scale vertically or horizontally.
- Replication & Clustering: Supports data replication and clustering for high availability and load balancing.
- Storage Engines: Offers multiple storage engines like InnoDB (supports transactions) and MyISAM (faster for read-heavy operations).
- Security: Provides authentication, access control, and SSL encryption.
🚀 Basic MySQL Commands
- Create Database
CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), email VARCHAR(100) UNIQUE, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
- Insert Data
INSERT INTO users (name, email) VALUES ('John Doe', 'john@example.com');
- Fetch Data
SELECT * FROM users;
- Update Data
UPDATE users SET name = 'Jane Doe' WHERE id = 1;
- Delete Data
DELETE FROM users WHERE id = 1;
🛠️ MySQL and Go Fiber
Since you're working with Go Fiber, you can use a MySQL driver like github.com/go-sql-driver/mysql
to connect to your database. Example:
import ("database/sql""fmt"_ "github.com/go-sql-driver/mysql")func main() {db, err := sql.Open("mysql", "user:password@tcp(localhost:3306)/mydb")if err != nil {panic(err)}defer db.Close()fmt.Println("Connected to MySQL")}