---
# System prepended metadata

title: mariaDB

---

# mariaDB

## 安裝
```
yum install mariadb
yum install mariadb-server
```
## 啟用&自啟動
```
systemctl start mariadb
systemctl enable mariadb
```
## 安全性設定
```
sudo mysql_secure_installation
```
## 登入
```
mysql -u root -p
```
## 升級
1. 加入MariaDB YUM庫
```bash
vi /etc/yum.repos.d/MariaDB.repo
```
內容
```
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
```
2. 備份資料庫&設定檔(全新安裝可跳過)
```bash
mysqldump -u root -p --all-database > all.sql
cp /etc/my.cnf /etc/my.cnf.bak
```
3. 停止MariaDB服務(全新安裝可跳過)
```
systemctl stop mariadb
```
4. 移除舊版本MariaDB(全新安裝可跳過)
```
yum remove mariadb mariadb-server
```
5. 安裝新版MariaDB
```bash
yum install mariadb mariadb-server
```
6. 啟用MariaDB服務&自啟動
```
systemctl enable --now mariadb
```
7. 升級原有資料庫(全新安裝可跳過)
```bash
mysql_upgrade -u root -p
```


## 重置MySql自動增量值
mysql
`truncate table + table名稱;`