---
# System prepended metadata

title: 建立 MySQL 資料庫伺服器

---

---
title: '建立 MySQL 資料庫伺服器'
disqus: hackmd
---

建立 MySQL 資料庫伺服器
===

組別:一個人很痛苦所以兩個人吧
* D0987305 陳煒明(報告 實作)
* D0978214 程彥璋(實作)

mysql設計
---
利用特權給與而非使用php5來連線操作
使用mariadb來安裝資料庫
![](https://i.imgur.com/HvBOtSJ.png)

指令安裝
---
```linux
sudo apt-get -f install default.mysql.server
sudo mysql -u root
```
![](https://i.imgur.com/9ut1WF7.png)

![](https://i.imgur.com/3FWGKGP.png)

安裝mysql server
---
```
pi@www: sudo mysql
[mysql]default-character-set = utf8;
[mysql]set password for root@localhost = password(‘第一空格處’);
```
![](https://i.imgur.com/4eyRzNp.png)
```
[mysql]create database FAKE;
[mysql]grant all privileges on FAKE.* to test@% identified by ‘第二空格處‘);
[mysql]Flush privileges;
[mysql]exit
(第一空格處=你的密碼) (第二空格處=配置特權)

```
```
pi@www: mysql_secure_installation
…
Enter current password for root(enter for none):
…
set root password?[y/n]y (recommened)
…
Remove anonymous users?[y/n] y (recommened)
…
Disallow root login?[y/n] y (recommened)
...
Remove testdase and access to it?[y/n]y
…
Reload privilege tables now?[y/n] y
…
```
```
/etc/mysql/mariadb.conf.d(terminal)
**需要超級用戶權限**
```
![](https://i.imgur.com/242Ro7Q.png)
```
edit (bind-address=127.0.0.1)
->(bind-address=0.0.0.0)/
(#bind-address=127.0.0.1)
```
![](https://i.imgur.com/ASbV3z6.png)
```
edit(# port=3306)->(port=3306)
```
![](https://i.imgur.com/wm7xm1a.png)
```
pi@www: sudo systemctl restart mysql
```

防火牆配置
---

```
pi@www: sudo iptables -A INPUT -p tcp --destination-port 3306 -j ACCEPT
OR
sudo iptables -A INPUT -s  空格處  -p tcp --destination-port 3306 -j ACCEPT	(只限特定 ip)

空格處=ip

```
操作說明
---
選取資料庫來建立或連接
![](https://i.imgur.com/C1QAJx3.png)

設定連線方式
我們使用直接連線(ODBC : client端需有MyODBC才能使用)
(JDBC : 使用Java語言來操作資料庫)
![](https://i.imgur.com/RBpVT5y.png)

設定資料庫伺服器連線的位址
(伺服器位址採用lan ip)
![](https://i.imgur.com/KTF1TsU.png)

設定使用者名稱認證
![](https://i.imgur.com/dXC3xbG.png)



## 參考連結

:::info

https://phoenixnap.com/kb/mysql-remote-connection
[Configuring MariaDB for Remote Client Access - MariaDB Knowledge Base](https://mariadb.com/kb/en/configuring-mariadb-for-remote-client-access/)
[安装mariadb 并更改mysql默认root密码_阿拨次得的博客-CSDN博客_mariadb root默认密码](https://blog.csdn.net/makemeiyouboluo/article/details/87856818)

:::

