|
@@ -1,28 +1,29 @@
|
|
|
# mysql server installation and configuration on Ubuntu Server 22.04
|
|
|
|
|
|
+*Reference titles:*
|
|
|
+
|
|
|
+*https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-22-04*
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
1. Update ubuntu server first:
|
|
|
+
|
|
|
```console
|
|
|
sudo apt update
|
|
|
```
|
|
|
|
|
|
-
|
|
|
-
|
|
|
2. Then upgrade ubuntu server:
|
|
|
|
|
|
```console
|
|
|
sudo apt upgrade
|
|
|
```
|
|
|
|
|
|
-
|
|
|
-
|
|
|
3. Install mysql server:
|
|
|
|
|
|
```console
|
|
|
sudo apt install mysql-server
|
|
|
```
|
|
|
|
|
|
-
|
|
|
-
|
|
|
4. Start mysql service:
|
|
|
|
|
|
```console
|
|
@@ -35,6 +36,84 @@
|
|
|
|
|
|
![image-20230627172104628](doc/readme/img/install_and_configure_mysql_server_on_ubuntu/image-20230627172104628.png)
|
|
|
|
|
|
+5. Start mysql initial configuration:
|
|
|
+
|
|
|
+ ```console
|
|
|
+ sudo mysql_secure_installation
|
|
|
+ ```
|
|
|
+
|
|
|
+ Do it step by step following the prompt.
|
|
|
+
|
|
|
+5. Grant specific ip to access this mysql server.
|
|
|
+
|
|
|
+ Enter mysql console:
|
|
|
+
|
|
|
+ ```console
|
|
|
+ sudo mysql -u root -p
|
|
|
+ ```
|
|
|
+
|
|
|
+ Create root user for specific ip:
|
|
|
+
|
|
|
+ ```console
|
|
|
+ CREATE USER 'root'@'your-specific-ip' IDENTIFIED WITH mysql_native_password BY 'your-password';
|
|
|
+ ```
|
|
|
+
|
|
|
+ Grant specific ip to access mysql:
|
|
|
+
|
|
|
+ ```console
|
|
|
+ GRANT ALL PRIVILEGES ON *.* TO 'root'@'your-specific-ip' WITH GRANT OPTION;
|
|
|
+ ```
|
|
|
+
|
|
|
+ ```console
|
|
|
+ FLUSH PRIVILEGES;
|
|
|
+ ```
|
|
|
+
|
|
|
+ ```console
|
|
|
+ exit;
|
|
|
+ ```
|
|
|
+
|
|
|
+6. Configure your mysql server to allow dedicated IPs to access.
|
|
|
+
|
|
|
+ First, backup mysql server configuration file:
|
|
|
+
|
|
|
+ ```console
|
|
|
+ sudo cp /etc/mysql/mysql.conf.d/mysqld.conf /etc/mysql/mysql.conf.d/mysqld.conf.bak
|
|
|
+ ```
|
|
|
+
|
|
|
+ Second, edit the configuration file to allow remote access. Open mysqld.conf and edit:
|
|
|
+
|
|
|
+ ```console
|
|
|
+ sudo vim /etc/mysql/mysql.conf.d/mysqld.conf
|
|
|
+ ```
|
|
|
+
|
|
|
+ Change bind-address from 127.0.0.1 to 0.0.0.0:
|
|
|
+
|
|
|
+ ![image-20230627183522646](doc/readme/img/mysql_server_installation_and_configuration_on_Ubuntu_Server_22.04/image-20230627183522646.png)
|
|
|
+
|
|
|
+ Save the file and quit (via vim wq).
|
|
|
+
|
|
|
+7. Restart mysql service:
|
|
|
+
|
|
|
+ ```console
|
|
|
+ sudo systemctl restart mysql
|
|
|
+ ```
|
|
|
+
|
|
|
+8. Configure mysql server to allow remote access from specific ip.
|
|
|
+
|
|
|
+9. For security reasons, **NEVER** allow any unknown ip address to access your server. Enable and configure your firewall to allow dedicated IPs to access mysql serivice on this server:
|
|
|
+
|
|
|
+ ```console
|
|
|
+ sudo ufw enable
|
|
|
+ sudo ufw allow from <your-specific-ip> to any port 3306
|
|
|
+ sudo ufw reload
|
|
|
+ sudo ufw status
|
|
|
+ ```
|
|
|
+
|
|
|
+
|
|
|
+ If everything is configured correctly, you'll see things like this:
|
|
|
+
|
|
|
+ ![image-20230627182439999](doc/readme/img/mysql_server_installation_and_configuration_on_Ubuntu_Server_22.04/image-20230627182439999.png)
|
|
|
|
|
|
+10. Now you can test the connection to mysql server through Navicat:
|
|
|
|
|
|
-5.
|
|
|
+ ![image-20230627185346672](doc/readme/img/mysql_server_installation_and_configuration_on_Ubuntu_Server_22.04/image-20230627185346672.png)
|