Skip to content

mariadb install ​

shell
$ sudo apt install mariadb-server -y

設定檔 /etc/mysql log /var/log/mysql

服務使用

shell
$ sudo systemctl start mysql.service
$ sudo systemctl stop mysql.service
$ sudo systemctl restart mysql.service
$ sudo systemctl status mysql.service

mariadb connect ​

shell
$ sudo mysql # 預設無密碼登入
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 43
Server version: 10.0.38-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

with password login mariadb ​

shell
$ mysql -h HOST -u USER -p PASSWORD

mariadb 設定密碼

shell
$ sudo mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 45
Server version: 10.0.38-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> UPDATE user set password=PASSWORD("passw0rd") WHERE User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> UPDATE user set plugin='' WHERE User='root'; # 移除免密碼設定
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]>

Mysql Database Management ​

create Database ​
shell
MariaDB [(none)]> CREATE DATABASE wordpress; # 建立資料庫
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| wordpress          |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]>
selection database ​
shell
MariaDB [(none)]> use wordpress; # 使用 use 切換要使用的 DB
Database changed
delete database ​
shell
MariaDB [wordpress]> DROP database wordpress; # DROP 刪除 DB
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]>
Back up a database ​
shell
$ mysqldump DESTINATION_DB -u USER -p > BACKUP_FILE_NAME
Back up all databases ​
shell
$ mysqldump -all-databases -u USER -p > BACKUP_FILE_NAME
mysqladmin ​

算是一個管理 Mysql 的指令。

shell
$ mysqladmin -uroot -pPASSWORD create DB_NAME
$ mysqladmin -uroot -pPASSWORD drop DB_NAME
$ mysqladmin -uroot -pPASSWORD shutdown

Built with VitePress