To follow this module you need to prepare 3 things:
world
database in DBeaverThis guide provides step-by-step instructions on how to install these on different operating systems: macOS, Ubuntu, and Windows.
[!WARNING] If you’re using a different operating system, please find your way through other resources.
Open your Terminal.
Install Homebrew if you haven’t already:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
$ brew install mysql
$ brew services start mysql
[!TIP] If you install MySQL via Homebrew, the default username is
root
, and there is no password.
Open your Terminal.
Update the package list:
$ sudo apt update
sudo apt install mysql-server
During the installation, you’ll be prompted to set a root password for MySQL.
Start the MySQL service:
sudo service mysql start
Visit the MySQL APT repository page: MySQL APT Repository.
Download the repository package for Ubuntu and install it.
Update the package list:
$ sudo apt update
$ sudo apt install mysql-server
During the installation, you’ll be prompted to set a root password for MySQL.
Start the MySQL service:
$ sudo service mysql start
Download the MySQL Installer for Windows from the official website: MySQL Downloads.
Run the installer executable and follow the installation wizard’s instructions.
During installation, set up a root password for MySQL.
Choose the components you want to install. Select at least MySQL Server.
Once the installation is complete, start the MySQL service using the MySQL Command Line Client or MySQL Workbench.
[!IMPORTANT] Store the password you chose in a secure but handy place. You’re going to need it throughout the module.
To verify that MySQL is installed and running, open your Terminal or Command Prompt and run the following command:
$ mysql -u root -p
You will be prompted to enter the root password you set during installation. If MySQL is successfully running, you will be logged into the MySQL command-line interface.
You can interact with a MySQL database directly from your terminal using the mysql
shell. However, it’s more convenient to use a separate application - a SQL client.
DBeaver is a free, open source SQL client that works on macOS, Linux, and Windows that supports MySQL and many others SQL database engines. We recommend installing and using it during the module.
$ sudo add-apt-repository ppa:serge-rider/dbeaver-ce
$ sudo apt-get update
$ sudo apt-get install dbeaver-ce
world
databaseFor the exercises we’ll be using an example database (world
), so we must set it up.
To install the sample database, follow these steps:
$ git clone git@github.com:HackYourFutureBelgium/sql-database.git
$ cd sql-database
world
database:$ mysql -u "root" -p < "week1/databases/world.sql" # enter your password when asked
This will connect to your MySQL server and execute the world.sql
script.
world
database is installed correctly.$ mysql -u "root" -p # enter your password when asked
mysql> USE world;
mysql> SHOW TABLES;
You should see an output similar to the following:
+-----------------+
| Tables_in_world |
+-----------------+
| city |
| country |
| countrylanguage |
+-----------------+
3 rows in set (0.00 sec)
MySQL
as driverlocalhost
world
root
<your-password>
(can be blank if you installed via Homebrew)You should now see the world
database and its tables on the Database Navigator:
world -> SQL Editor -> New SQL console
SHOW TABLES;
If you see the sample above, everything is ok! You have successfully connected to the world
database and can follow along to this week’s Readings and Exercises).