
MySQL is an open-source relational database management system (RDBMS) that uses the SQL (Structured Query Language) syntax to create, manage, and manipulate databases on a server. MySQL works as a reliable database server for small, medium, and large-scale applications to offer continuous record interaction, reliability, and high performance.
This article explains how to install MySQL on FreeBSD 14.0, secure the database server, and enable authenticated access to the database console.
Before you begin, you need to:
MySQL is available in the default FreeBSD 14.0 repositories with multiple versions and add-on packages. Follow the steps below to install the latest MySQL database server package using the default pkg package manager.
Update the server package index.
Search all MySQL packages available in the default repositories.
Your output should look like the one below:
Based on the above output, MySQL 8.1 is the latest version available in the default repository catalog. Compile and install MySQL using the latest FreeBSD ports collection information to install unavailable versions on your server.
Install the latest MySQL package on your server.
View the installed MySQL version on your server.
Output:
MySQL uses the mysql-server system service to control the database server processes and runtime on your FreeBSD server. Follow the steps below to enable the MySQL service to start at boot time and verify the service status to manage the database processes on your server.
Enable MySQL to start automatically at boot time.
Output:
Start the MySQL service.
View the MySQL service status and verify that it's running.
Output:
Stop the MySQL service.
Restart the MySQL server.
MySQL uses the mysql_secure_installation script to remove insecure defaults such as databases and enable authentication for all database users on your server. Follow the steps below to run the script, set up a new root database user password, remove anonymous users, and disable test databases on your server.
Run the MySQL secure installation script.
Reply to each of the following prompts to secure your MySQL database server.
root database user password.Output:
root database user.Output:
Restart the MySQL database server to apply your configuration changes.
You can use the mysql CLI utility to access the MySQL database server console or application modules such as php-mysqli to integrate MySQL with other applications such as PHP. Follow the steps below to access the MySQL console and create sample database records on your server.
Log in to the MySQL database server as root.
Enter the root database user password you created earlier when prompted to access the MySQL console. Your output should be similar to the one below when successful.
Create a new sample database. For example, example_vultr.
View all databases on your server and verify that the new database is available.
Output:
Create a new sample database user vultr_user with a strong password. Replace STRONG-PASSWORD with your desired password.
Grant the new user full privileges to the example_vultr database.
Reload the MySQL privileges table to apply changes.
Switch to the example_vultr database.
Create a new sample table sample_users with five columns to store different data types.
The above SQL query creates a new table with the following columns and data types:
id: Automatically increments the value for each new record using the AUTO_INCREMENT function. The PRIMARY KEY attribute ensures that each record is unique in the table.name: Stores user names with up to 50 mixed characters.email: Stores user email addresses with up to 100 mixed characters. The UNIQUE attribute ensures that each email address is unique across all records.phone: Stores user phone numbers with up to 20 mixed characters.created_at: Automatically stores the timestamp when a record is created.Insert new sample data into the sample_users table.
View all records in the sample_users table to verify that the new data is available.
Output:
Exit the MySQL console.
You have installed MySQL on your FreeBSD 14.0 server and secured the database server to require authentication for all database users. You can use the MySQL database server as a dedicated backend by modifying the main configuration to listen for connections from a specific address such as a VPC network. In addition, you can install add-on modules to use MySQL with other applications such as PHP on your server. For more information about MySQL, visit the official documentation.
0 Comments
Be the first to comment and share your perspective with the community.