Terminal command line
因為此操作需要用到 root 權限,因此開始前會先 sudo su ,切換到 root 使用者。
#切換到 root 權限
aiot@aiot-1-i534:~$ sudo su
[sudo] password for aiot: ********
#更新 apt-get
root@aiot-1-i534:/home/aiot# apt update
root@aiot-1-i534:/home/aiot# apt upgrade -y
#安全 MySQL 及相關工具
root@aiot-1-i534:/home/aiot# apt install mysql-server vim net-tools -y
#設定 MySQL 權限
root@aiot-1-i534:/home/aiot# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.30-0ubuntu0.22.04.1 (Ubuntu)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or it affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
#建立使用者(username:hc, password:123456789, host: %)
mysql> CREATE USER 'hc'@'%' IDENTIFIED BY '123456789';
Query OK, 0 rows affected (0.03 sec)
#為使用者設定權限
mysql> GRANT ALL PRIVILEGES ON *.* TO 'hc'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.04 sec)
#資料庫套用權限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.03 sec)
mysql> quit
Bye
#設定 MySQL 可從外部連入
root@aiot-1-i534:/home/aiot# vim /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = *
mysqlx-bind-address = *
#重啟 MySQL
root@aiot-1-i534:/home/aiot# service mysql restart
#設定 MySQL 於開機自動啟動
root@aiot-1-i534:/home/aiot# systemctl enable mysql
#允許防火牆接受 3306 Port 連入
root@aiot-1-i534:/home/aiot# ufw allow 3306
Skipping adding existing rule
Skipping adding existing rule (v6)