# How To Install MySQL on Ubuntu 22.04

MySQL is an open source relational management system, that uses structured query language for database access and management. Mysql is commonly used in web applications, data warehousing, e-commerce, and logging applications.&#x20;

{% embed url="<https://youtu.be/1wqysVpnjGM?si=HIlylFVld14ptQZi>" %}

## Prerequisites&#x20;

* Launch the [Ubuntu 22.04 instance](https://docs.neevcloud.com/neevcloud-products/computes/getting-started-launch-vms) on Neevcloud
* Access the server using [SSH](https://docs.neevcloud.com/neevcloud-products/computes/getting-started-launch-vms#ssh)

## Update && Upgrade the system <a href="#update-and-and-upgrade-the-system" id="update-and-and-upgrade-the-system"></a>

First, ensure your package list is up to date to avoid any issues with outdated packages

```
sudo apt-get update -y
sudo apt-get upgrade -y
```

<figure><img src="/files/Y4ZKfUF8k9ku0vRxcupA" alt=""><figcaption></figcaption></figure>

## Install MySQL <a href="#install-nginx" id="install-nginx"></a>

To install MySQL, use the `apt` package manage and run the following command from a terminal prompt:

```
sudo apt-get install mysql-server -y
```

### Start and Enable MySQL <a href="#start-and-enable-nginx" id="start-and-enable-nginx"></a>

Once the MySQL is installed, start the MySQL server

```
sudo systemctl start mysql
```

Enable it to start when the system rebooted

```
sudo systemctl enable mysql
```

<figure><img src="/files/JbQ3NzB95XGe1s3qWfvq" alt=""><figcaption></figcaption></figure>

### To check the status&#x20;

The MySQL server should be started. You can quickly check its current status

```
sudo systemctl status mysql
```

<figure><img src="/files/hzNsBnoKnkakVkivS36I" alt=""><figcaption></figcaption></figure>

### The Network status of the MySQL service

The network status of the MySQL service can also be checked by running the `ss` command at the terminal prompt

```
sudo ss -antpl | grep mysql
```

<figure><img src="/files/jUfH6sXRw5e61sYVvO6S" alt=""><figcaption></figcaption></figure>

## Configure MySQL

When the installation is finished, it’s recommended that you run a security script that comes pre-installed with MySQL. This script will remove some insecure default settings and lock down access to your database system.

you can access normally MySQL database.

```
sudo mysql
```

<figure><img src="/files/FKVtUv37lUT9nTr04yli" alt=""><figcaption></figcaption></figure>

### MySQL Secure Installation

Start the interactive script by running, This will take you through a series of prompts where you can make some changes to your MySQL installation’s security options

```
sudo mysql_secure_installation
```

This will ask if you want to configure the VALIDATE PASSWORD PLUGIN.

Answer Y for yes, or anything else to continue without enabling.

<figure><img src="/files/xT4UoUZRw1MhOSrcgAsc" alt=""><figcaption></figcaption></figure>

If you select "Yes," you'll need to choose a password validation level. Note that choosing the highest level `2`means your passwords must include numbers, uppercase and lowercase letters, and special characters. Otherwise, you'll encounter errors.

<figure><img src="/files/bW5nOwjd9qZpvaRT3wbl" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/0oThpewdzg86YczW2Gl5" alt=""><figcaption></figcaption></figure>

After the security script finishes running, you can proceed to reopen MySQL and revert the root user's authentication method to the default, auth\_socket. To verify your identity as the main MySQL user with a password, execute this command

```
sudo mysql -u root -p 
```

After executing the commands, please enter your password:

<figure><img src="/files/74AUNKcjhzgN6W0TmIbI" alt=""><figcaption></figcaption></figure>

### Create a MySQL User <a href="#creating-a-mysql-database" id="creating-a-mysql-database"></a>

Once you have access to the MySQL prompt, you can create a new user with a `CREATE USER` statement. To create a user login MySQL just like this **\[  mysql> ]**

<pre><code><strong>CREATE USER 'username'@'host' IDENTIFIED WITH authentication_plugin BY 'password';
</strong></code></pre>

* **Grant Privileges to MySQL User**

```
GRANT ALL PRIVILEGES ON *.* TO 'user_name'@localhost IDENTIFIED BY 'password1';
```

### Creating a MySQL Database

To create a database in **MySQL**, follow these steps:

{% hint style="info" %}
Log into MySQL with the command `mysql -u username -p`. Replace `username` with your MySQL username. You'll be prompted to enter your password.
{% endhint %}

{% hint style="info" %}
Once logged in, create a new database by executing `CREATE DATABASE database_name;`. Replace `database_name` with your desired database name.
{% endhint %}

{% hint style="info" %}
To verify the database was created, use `SHOW DATABASES;`. Your new database should appear in the list.
{% endhint %}

To create a new database, run the following command from your **MySQL** console just like **\[ mysql> ]**&#x20;

```
CREATE DATABASE database_name;
```

* **User and database permission**

Once you have set up a new user and database, you can give them the necessary permissions.

```
GRANT ALL PRIVILEGES ON database_name.*  TO  'username'@'%';
```

Now, review MySQL configurations.

```
sudo mysql -u root -p 
```

Now check the status databases to run these command&#x20;

```
show databases;
```

<figure><img src="/files/rlPC6clJxJrYJva1h6MS" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.neevcloud.com/neevcloud-guide/neevcloud-knowledgebase/how-to-install-mysql-on-ubuntu-22.04.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
