0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
JPPINTO
  • Home
  • Blog
  • Certifications
  • About
  • Contact
  • Shop
  • Gallery
  • Current Setup
Contact

Search

July 3, 2026 / Linux, Servers, Ubuntu

Install and Configure MySQL on Ubuntu for WordPress

Tags: database, linux, mysql, server setup, ubuntu, wordpress
Featured image for Install and Configure MySQL on Ubuntu for WordPress

MySQL is a common database choice for WordPress and many PHP applications. On Ubuntu, you can install it from the default package repositories and then apply a small performance configuration for local web hosting.

This guide uses generic placeholders for usernames and passwords. Do not hard-code real production passwords in public scripts, documentation, Git repositories, or screenshots.

What the Script Does

The deployment script this article is based on:

  • Installs mysql-server.
  • Enables and starts the MySQL service.
  • Creates an admin user for local socket access.
  • Backs up the MySQL configuration.
  • Writes a custom performance config file.
  • Validates the MySQL configuration.
  • Restarts MySQL and tests login again.

Install MySQL

Run:

sudo apt update
sudo DEBIAN_FRONTEND=noninteractive apt install -y mysql-server
sudo systemctl enable mysql
sudo systemctl start mysql
sudo systemctl is-active --quiet mysql

You can open the MySQL shell as root with:

sudo mysql

Create an Admin User

Use your own username and a strong password:

MYSQL_ADMIN_USER="dbadmin"
MYSQL_ADMIN_PASSWORD="<REPLACE_WITH_STRONG_PASSWORD>"

Create the user:

sudo mysql <<MYSQL_SCRIPT
CREATE USER IF NOT EXISTS '${MYSQL_ADMIN_USER}'@'localhost' IDENTIFIED BY '${MYSQL_ADMIN_PASSWORD}';
GRANT ALL PRIVILEGES ON *.* TO '${MYSQL_ADMIN_USER}'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
MYSQL_SCRIPT

Test the user:

mysql --protocol=socket -u "${MYSQL_ADMIN_USER}" -p -e "SELECT VERSION();"

Type the password when prompted.

Avoid putting the real password directly on the command line, because command-line arguments may be visible in shell history or process listings.

Back Up the MySQL Config

Create a backup folder:

sudo mkdir -p /opt/server-backups/mysql
timestamp="$(date +%Y%m%d%H%M%S)"

Back up the main MySQL config if it exists:

if [ -f /etc/mysql/mysql.conf.d/mysqld.cnf ]; then
    sudo cp /etc/mysql/mysql.conf.d/mysqld.cnf "/opt/server-backups/mysql/mysqld.cnf.before.${timestamp}.bak"
fi

Write a Custom Performance Config

Create a custom config file:

sudo tee /etc/mysql/mysql.conf.d/99-custom-performance.cnf >/dev/null <<EOF
[mysqld]
port = 3306
bind-address = 127.0.0.1

innodb_buffer_pool_size = 4G
max_connections = 200
tmp_table_size = 256M
max_heap_table_size = 256M

innodb_flush_log_at_trx_commit = 1
innodb_file_per_table = 1
skip_name_resolve = ON
EOF

The bind-address = 127.0.0.1 setting keeps MySQL listening locally. That is a good default when web applications connect from the same server.

For remote administration, use an SSH tunnel instead of exposing MySQL directly to the internet.

Validate and Restart MySQL

Validate the config:

sudo mysqld --validate-config

If validation succeeds, restart MySQL:

sudo systemctl restart mysql
sudo systemctl is-active --quiet mysql

Test login again:

mysql --protocol=socket -u "${MYSQL_ADMIN_USER}" -p -e "SELECT VERSION();"

Back up the custom config:

sudo cp /etc/mysql/mysql.conf.d/99-custom-performance.cnf "/opt/server-backups/mysql/99-custom-performance.cnf.after.${timestamp}.bak"

Troubleshooting

If MySQL does not restart, check:

sudo journalctl -u mysql -xe
sudo mysqld --validate-config

If login fails, confirm the user exists:

sudo mysql -e "SELECT user, host FROM mysql.user;"

Quick Reference

sudo apt install -y mysql-server
sudo systemctl enable mysql
sudo mysqld --validate-config
sudo systemctl restart mysql
sudo mysql

Keep database credentials private. Use placeholders in documentation, prompt for passwords when possible, and never publish real passwords in scripts.

Post Views: 27
<- Install PHP-FPM and Common PHP Extensions on Ubuntu
Install and Configure Redis on Ubuntu for Local Object Cache ->

Categories

  • Active Directory (5)
  • AI (2)
  • Amazon Cloud Services (1)
  • Blazor (1)
  • C# (C-Sharp) (3)
  • CI/CD Pipelines (1)
  • Containers (4)
  • Deployment (2)
  • Development (4)
  • Docker (3)
  • General (5)
  • IIS 6.0 (4)
  • IIS 7.0 (10)
  • IIS 8.0 (1)
  • Infrastructure as Code (IaC) (1)
  • Kubernetes (3)
  • Linux (8)
  • Microsoft 365 (2)
  • MySQL (1)
  • Office 2010 (1)
  • PHP (1)
  • PowerShell (7)
  • Productivity (1)
  • Servers (8)
  • SharePoint 2007 (8)
  • SharePoint 2010 (19)
  • SharePoint 2013 (2)
  • SharePoint Online (1)
  • SMTP (4)
  • SQL Server 2008 (1)
  • SQL Server 2008 R2 (1)
  • SQL Server 2012 (2)
  • SQL Server 2019 (1)
  • Ubuntu (8)
  • Uncategorized (1)
  • URL Rewrite (2)
  • Visual Studio 2019 (1)
  • Visual Studio Code (1)
  • Windows 10 (5)
  • Windows 2003 (9)
  • Windows 2008 (18)
  • Windows 2012 (6)
  • Windows 7 (3)
  • Windows Firewall (1)
  • Windows Vista (1)
  • WordPress (3)
  • WP-CLI (3)

Recent Posts

  • Create an Nginx Default Catch-All Site on Ubuntu
  • Install and Configure Redis on Ubuntu for Local Object Cache
  • Install and Configure MySQL on Ubuntu for WordPress
  • Install PHP-FPM and Common PHP Extensions on Ubuntu
  • Install and Tune Nginx on Ubuntu for Web Hosting

Advertisement

Tags

ai coding agents bash developer workflow dev to production exe permissions externalize blob externalize sharepoint data filezilla server firewall rules filazilla full installation http redirect https https redirect IIS iis7 iis 7 installation IIS installation index server configuration installing cumulative updates linux load balance central administration microsoft 365 nginx nlb powerpoint powershell redirect http to https server setup sharepoint 2010 cumulative updates sharepoint 2010 farm build sharepoint 2010 farm configuration sharepoint 2010 farm installation sharepoint data externalization SMTP storagepoint ubuntu web server windows Windows 7 windows firewall configuration windows server 2008 wlbs wordpress wp-cli x86
© 2026 JPPinto.com. All rights reserved.