-

Intro to databases

Typically, anyone writing an application will at some point interact with a database server and in most cases, this database server will be MYSQL.

SQL vs NoSQL

SQL databases offer structured schemas and strong data consistency, making them ideal for applications requiring data accuracy and complex querying. However, their rigid schema can be inflexible and challenging to adapt, and they may struggle with horizontal scaling.

NoSQL databases provide a flexible, schema-less approach, making them suitable for evolving data structures and scalable for high volumes of unstructured data. They excel in distributed environments but may sacrifice strong consistency and lack standardized query languages. The choice between SQL and NoSQL depends on specific application requirements, with SQL offering data integrity and querying capabilities, while NoSQL provides flexibility and scalability for dynamic data needs.

What Are the advantages of using a database server?

The advantages of a database server are multiple:

  • Queries can be made to data in a much faster way, especially when there are many concurrent queries
  • It is easier to scale a database server as needed, using replication as needed.
  • sql syntax is relatively standard and allows for portable code across database servers
  • data can be accessed easily through apis in multiple programming environments
  • there is a security api included with the sql server which allows for better data security as well as integrity through things such as transactions

Things to be aware of when using a database server

Here's a table summarizing the top 10 database servers, including PostgreSQL, MySQL, MongoDB, Redis, and others, along with their advantages and weaknesses:

Database Server Advantages Weaknesses
PostgreSQL - ACID compliant - Can be resource-intensive
- Supports complex queries and joins - Steeper learning curve for beginners
- Extensive community support
MySQL - Fast and reliable - Limited support for NoSQL
- Well-documented - InnoDB storage engine may require tuning
- Widely used in web applications
MongoDB - NoSQL, schema-less - Not suitable for complex transactions
- High scalability and flexibility - Limited support for joins
- Excellent for handling unstructured data
Redis - In-memory data store - Limited data persistence options
- Ultra-fast read and write operations - Not suitable for complex querying
- Supports various data types
Oracle - Proven enterprise-grade database - Expensive licensing and support
- High performance and scalability - Complex to set up and administer
- Comprehensive security features
SQL Server - Robust features for business applications - Proprietary, costly licensing
- Integration with Microsoft technologies - Limited cross-platform support
- Excellent performance and scalability
Cassandra - Scalable and distributed - Complex data modeling
- High availability and fault tolerance - Eventual consistency model
- Excellent for time-series and IoT data
SQLite - Embedded, serverless database - Limited concurrency support
- Lightweight and easy to use - Not suitable for high-traffic applications
- Ideal for mobile and desktop applications
Couchbase - NoSQL, distributed - Limited advanced querying capabilities
- High performance and low latency - Smaller community compared to some others
- Supports JSON and SQL-like querying
MariaDB - MySQL fork with enhancements - Smaller ecosystem compared to MySQL
- Open-source and community-driven - Limited proprietary features
- High performance and compatibility with MySQL

These databases cater to a wide range of use cases and offer different strengths and weaknesses, so the choice depends on the specific requirements of your application.

Here are a couple of tips:

  • if data is going to be used multiple times, data caching can speed up very easily web page access as well as decrease processor resources being hit
  • if many queries are to be done, a well placed index can decrease page processing speed as well as optimise resource use.
  • If many inserts / deletes/ updates are to be done, using transactions can greatly improve performance
  • There are cases where a simple flat text file can do the job faster and in a much easier way
  • Using a GUI tool like phpmyadmin can make your life a lot easier by providing CRUD functionality (create read update delete) through a graphical interface to databases. It also makes creation, editing of databases themselves easier and less error prone.
  • Make sure you password phpmyadmin access if the server is going to be publically accessible, Preferably, do not put it in the default /phpmyadmin/ path to maximise security.

It is also interesting to note that in many cases (especially if the queries are simple), when a mysql server is not available sqlite can be an excellent alternative providing fast performance and small memory foot print… sometimes very easily by simply slightly changing the function names (which are very similar).

If sqlite is used, make sure the database files are protected from unauthorized web access either by putting them outside the web server document root or with an appropriate htaccess entry. Notes about queries

Note:

  • Mysql queries end in a semi column or in the monitor, with g
  • Several queries can be put in one string