In this lesson you get a MySQL server running, lock it down and create the orbit database and account the rest of the course uses. Pick the section for your system; you only need one.
Choose a version
Install an LTS release: 8.4 if your hosting or framework documents it, otherwise 9.7. Both are in Oracle’s official repositories. Distribution repositories can lag behind or ship MariaDB under the mysql name, so the official ones are the safer choice.
Ubuntu and Debian
Oracle publishes an APT configuration package that adds its repository. Download the latest mysql-apt-config .deb from the MySQL APT repository page (dev.mysql.com/downloads/repo/apt/), then:
$ sudo dpkg -i mysql-apt-config_*_all.deb
$ sudo apt update
$ sudo apt install mysql-server
During dpkg -i a menu asks which series to track: choose mysql-8.4-lts or mysql-9.7-lts. The install asks for a root password and starts the service.
$ systemctl status mysql
$ mysql --version
mysql Ver 9.7.4 for Linux on x86_64 (MySQL Community Server - GPL)
Tip: Ubuntu’s own mysql-server package (without Oracle’s repository) is also real MySQL, usually a slightly older LTS. It is fine for learning; production servers usually prefer the official repository to get fixes sooner.
RHEL, Rocky Linux, AlmaLinux and Oracle Linux
These systems ship a mysql module in AppStream that may be older. Use Oracle’s Yum repository instead:
$ sudo dnf install https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm
$ sudo dnf module disable mysql
$ sudo dnf install mysql-community-server
$ sudo systemctl enable --now mysqld
The release RPM name contains the series and the EL version; check the Yum repository page for the current file name. On first start the server generates a temporary root password and writes it to the error log:
$ sudo grep 'temporary password' /var/log/mysqld.log
2026-11-11T09:12:44.512031Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: k;9Hs_wP2>rX
You must change it on first login before you can run any other statement.
Warning: In 2026 a repository update made some 8.4 servers jump to 9.7 during a routine dnf update. Check which LTS track is enabled with dnf repolist enabled | grep mysql before updating packages on a production server, and pin the track you want.
macOS
With Homebrew:
$ brew install mysql
$ brew services start mysql
$ mysql -u root
Homebrew’s mysql formula follows the newest release; install mysql@8.4 to stay on that LTS line. A Homebrew install starts with an empty root password for local connections, so run mysql_secure_installation (below) right away. Oracle also offers a .dmg installer with a System Settings pane.
Windows
Download the MySQL Installer or the MSI for your series from dev.mysql.com/downloads. The wizard:
- Installs the server and, if you choose, MySQL Shell and Workbench.
- Asks for a root password and optional extra accounts.
- Registers MySQL as a Windows service that starts with the system.
Afterwards open “MySQL 9.7 Command Line Client” from the Start menu, or add C:\Program Files\MySQL\MySQL Server 9.7\bin to PATH to run mysql in any terminal.
Docker
Containers are the fastest way to get a disposable server for learning:
$ docker run -d --name orbit-mysql \
-e MYSQL_ROOT_PASSWORD=change-me \
-p 3306:3306 \
-v orbit-mysql-data:/var/lib/mysql \
mysql:9.7
$ docker exec -it orbit-mysql mysql -u root -p
mysql:8.4andmysql:9.7track the latest patch of each LTS series. Pin a full version such asmysql:9.7.4in production so containers do not upgrade on their own.- The named volume
orbit-mysql-datakeeps your data when the container is removed. MYSQL_DATABASE,MYSQL_USERandMYSQL_PASSWORDcreate a database and account on first start, but this lesson does that by hand so you learn the SQL.
A minimal compose.yaml for local development:
services:
db:
image: mysql:9.7
environment:
MYSQL_ROOT_PASSWORD: change-me
ports:
- "3306:3306"
volumes:
- db-data:/var/lib/mysql
volumes:
db-data:
Secure the new server
Package installs come with a helper that tightens the defaults:
$ sudo mysql_secure_installation
It walks you through:
- Enabling the validate_password component, which rejects weak passwords.
- Setting or changing the root password.
- Removing anonymous accounts.
- Disallowing remote root login.
- Dropping the
testdatabase.
Answer yes to all of them on any server that is not a throwaway container.
Note: On Ubuntu and Debian, root@localhost often uses the auth_socket plugin: sudo mysql logs you in as root without a password because you are root on the operating system. That is safe and convenient for administration; applications should never connect as root anyway.
Where things live
| Item | Typical location (Linux) |
|---|---|
| Configuration | /etc/mysql/my.cnf and /etc/mysql/mysql.conf.d/ (Debian/Ubuntu), /etc/my.cnf and /etc/my.cnf.d/ (RHEL family) |
| Data directory | /var/lib/mysql |
| Error log | /var/log/mysql/error.log or /var/log/mysqld.log |
| Socket | /var/run/mysqld/mysqld.sock or /var/lib/mysql/mysql.sock |
| Service | mysql (Debian/Ubuntu) or mysqld (RHEL family) |
You can always ask the server itself:
SELECT @@datadir, @@port, @@socket, @@log_error;
+-----------------+--------+-----------------------------+--------------------------+
| @@datadir | @@port | @@socket | @@log_error |
+-----------------+--------+-----------------------------+--------------------------+
| /var/lib/mysql/ | 3306 | /var/run/mysqld/mysqld.sock | /var/log/mysql/error.log |
+-----------------+--------+-----------------------------+--------------------------+
1 row in set (0.00 sec)
The service is managed with systemd on Linux:
$ sudo systemctl stop mysql
$ sudo systemctl start mysql
$ sudo systemctl restart mysql
$ sudo journalctl -u mysql --since today
Create the Orbit database and account
Log in as root and create a database plus an account for the app. Every lesson from now on uses them.
$ sudo mysql
CREATE DATABASE orbit CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
CREATE USER 'orbit'@'localhost' IDENTIFIED BY 'Orbit-dev-2026!';
GRANT ALL PRIVILEGES ON orbit.* TO 'orbit'@'localhost';
Query OK, 1 row affected (0.01 sec)
Query OK, 0 rows affected (0.02 sec)
Query OK, 0 rows affected (0.01 sec)
utf8mb4stores any Unicode character, including emoji. Lesson 4 explains character sets and collations.- A MySQL account is user plus host:
'orbit'@'localhost'may only connect from the same machine. Lesson 18 covers accounts in depth. orbit.*means every object in theorbitdatabase, including tables created later.
Now connect as the new account:
$ mysql -u orbit -p orbit
The last orbit is the default database to use. If you see the mysql> prompt, you are ready for lesson 3.
Quick reference
| Task | Command |
|---|---|
| Install (Debian/Ubuntu) | sudo apt install mysql-server |
| Install (RHEL family) | sudo dnf install mysql-community-server |
| Start in Docker | docker run -d -e MYSQL_ROOT_PASSWORD=... mysql:9.7 |
| Secure a new install | sudo mysql_secure_installation |
| Service control | sudo systemctl restart mysql |
| Find temporary root password | sudo grep 'temporary password' /var/log/mysqld.log |
| Check the version | mysql --version |
Exercise
You installed MySQL on Rocky Linux from Oracle’s repository. How do you log in as root the first time?
Show answer
Answer: D. RHEL-family packages generate a random temporary root password at first start and log it. The account is marked expired, so the first statement you run must change it.
Exercise
What does the volume option in docker run -v orbit-mysql-data:/var/lib/mysql mysql:9.7 achieve?
Show answer
Answer: B. /var/lib/mysql is the data directory. Mounting a named volume there keeps the database files outside the container’s writable layer.
Exercise
Which account can connect to the server from another machine on the network?
Show answer
Answer: C. The host part restricts where a client may connect from. localhost and 127.0.0.1 only match local connections; % matches any host.
Key takeaways
- Install an LTS release (8.4 or 9.7) from Oracle’s official repository, Homebrew, the Windows installer or the official Docker image.
- Run
mysql_secure_installationon every real server. - Know where the configuration, data directory and error log live;
SELECT @@datadir, @@log_errortells you. - Applications get their own account limited to their own database, never root.
FAQ
I installed MySQL but SELECT VERSION() says MariaDB. What happened?
Some distributions, Debian among them, use MariaDB as their default “MySQL” (for example the default-mysql-server package). Add Oracle’s repository and install mysql-server or mysql-community-server from it to get Oracle MySQL.
Can I run two MySQL versions on one machine?
Yes, as long as each has its own data directory, port and socket. Containers make this trivial: run mysql:8.4 on port 3306 and mysql:9.7 on port 3307.
Do I need MySQL Workbench?
No. Everything in this course uses the mysql command-line client, which is always available on the server. Workbench, DBeaver, TablePlus and similar graphical tools are handy for browsing data and drawing diagrams, and you can use them alongside the terminal.
The server does not start after I edited my.cnf. Where do I look?
In the error log: sudo tail -50 /var/log/mysql/error.log or journalctl -u mysql. A misspelled option name is the most common cause; the log names the exact line MySQL did not understand.