0Pricing
Linux Server Deployment & SSH Mastery · Lesson

Installing PostgreSQL/MySQL

Learn to install and perform initial setup of either PostgreSQL or MySQL database servers on your Linux machine.

Installing PostgreSQL/MySQL is a free Linux Server Deployment & SSH Mastery lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Linux Server Deployment & SSH Mastery learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Databases: Your Server's Memory

Welcome! Database servers are essential for storing and managing data that your applications need. Think of them as the organized memory of your server.

In this lesson, you'll learn how to set up two of the most popular open-source database systems: PostgreSQL and MySQL.

PostgreSQL vs. MySQL

Both PostgreSQL and MySQL are powerful relational database management systems (RDBMS), but they have different strengths:

  • MySQL: Often preferred for web applications, easier to get started, good performance for read-heavy workloads.
  • PostgreSQL: Known for its advanced features, extensibility, strict adherence to SQL standards, and strong data integrity. Favored for complex applications and data warehousing.

You'll learn to install both, but you'll typically choose one based on your project's needs.

Update Your System First

Before installing any new software, it's always a good practice to update your server's package lists and upgrade existing packages. This ensures you have the latest security patches and dependencies.

Run this command in your terminal:

sudo apt update && sudo apt upgrade -y

Get PostgreSQL on Ubuntu

To install PostgreSQL on an Ubuntu-based system, you'll use the apt package manager. We'll install the main server and the postgresql-contrib package, which adds useful utilities.

Execute the following command:

sudo apt install postgresql postgresql-contrib -y

PostgreSQL Service & Status

After installation, PostgreSQL usually starts automatically. You can verify its status and ensure it's enabled to start on boot using systemctl commands:

sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo systemctl status postgresql

Install MySQL on Ubuntu

Now, let's install MySQL. Similar to PostgreSQL, we'll use apt to get the MySQL server package. This will install the database server and related client tools.

Run this command:

sudo apt install mysql-server -y

Secure Your MySQL Server

Immediately after installing MySQL, it's crucial to run the security script. This script helps you:

  • Set a strong root password
  • Remove anonymous users
  • Disallow remote root login
  • Remove test databases

Follow the prompts carefully:

sudo mysql_secure_installation

Accessing PostgreSQL

PostgreSQL creates a default administrative user called postgres. To connect to the database, you typically switch to this user and then use the psql command-line client.

Try connecting now:

sudo -i -u postgres
psql

Accessing MySQL

For MySQL, you can connect as the root user. Since we just ran mysql_secure_installation, you'll be prompted for the password you set.

Enter your root password when prompted:

sudo mysql -u root -p

Installation Check

You've installed and performed initial setup for both PostgreSQL and MySQL. Let's test your understanding of the security steps.

Databases: Ready for Data

Great job! In this lesson, you successfully learned how to:

  • Understand the differences between PostgreSQL and MySQL.
  • Install PostgreSQL and MySQL on an Ubuntu server using apt.
  • Verify and manage their services with systemctl.
  • Perform initial security setup for MySQL.
  • Connect to both database servers via the command line.

You now have a foundational understanding of setting up database servers. Next, you'll explore how to manage users and control access to your databases, enhancing their security!

Frequently asked questions

Is the “Installing PostgreSQL/MySQL” lesson free?

Yes — the full text of “Installing PostgreSQL/MySQL” is free to read here on the web, and the Linux Server Deployment & SSH Mastery course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Linux Server Deployment & SSH Mastery course, upgrade to CoddyKit PRO.

What will I learn in “Installing PostgreSQL/MySQL”?

Learn to install and perform initial setup of either PostgreSQL or MySQL database servers on your Linux machine. You practise Linux Server Deployment & SSH Mastery with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Linux Server Deployment & SSH Mastery?

No prior experience is required. Linux Server Deployment & SSH Mastery on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Installing PostgreSQL/MySQL” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Linux Server Deployment & SSH Mastery lesson?

Yes. Every Linux Server Deployment & SSH Mastery lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Installing PostgreSQL/MySQL
  2. Database User and Access Control
  3. Secure Database Connections
  4. Database Backup and Restore Strategies
← Back to Linux Server Deployment & SSH Mastery