Home · Guides / 4.2
Guide 4.2
Setup MySQL on Ubuntu
The original MySQL page was unpublished beyond a heading. These steps complete the LEMP companion for the NGINX and PHP guides: install MySQL on Ubuntu and keep it on localhost only.
-
Install MySQL Server from APT.
sudo apt update sudo apt install mysql-server -
Run the bundled hardening script and follow the prompts (set a root password if asked, remove anonymous users, disallow remote root, remove the test database, reload privileges).
sudo mysql_secure_installation -
Confirm MySQL is listening only on localhost.
sudo ss -nltp | grep mysqlYou want
127.0.0.1:3306, not0.0.0.0:3306. If needed, set this in/etc/mysql/mysql.conf.d/mysqld.cnfand restart:bind-address = 127.0.0.1sudo service mysql restart -
Create a database and a local user for your site. Do not create a user that can connect from
%.sudo mysqlCREATE DATABASE onion_site; CREATE USER 'onion'@'localhost' IDENTIFIED BY 'choose-a-strong-password'; GRANT ALL PRIVILEGES ON onion_site.* TO 'onion'@'localhost'; FLUSH PRIVILEGES; EXIT; -
Enable MySQL on boot.
sudo systemctl enable mysql.service
Why localhost only
The onion service already fronts HTTP on 127.0.0.1. MySQL should not be reachable from the network. PHP on the same host connects through
localhost or the local socket.