
- MariaDB 教程
- MariaDB - 首頁
- MariaDB - 簡介
- MariaDB - 安裝
- MariaDB - 管理
- MariaDB - PHP 語法
- MariaDB - 連線
- MariaDB - 建立資料庫
- MariaDB - 刪除資料庫
- MariaDB - 選擇資料庫
- MariaDB - 資料型別
- MariaDB - 建立表
- MariaDB - 刪除表
- MariaDB - 插入查詢
- MariaDB - 選擇查詢
- MariaDB - WHERE 子句
- MariaDB - 更新查詢
- MariaDB - 刪除查詢
- MariaDB - LIKE 子句
- MariaDB - ORDER BY 子句
- MariaDB - JOIN
- MariaDB - NULL 值
- MariaDB - 正則表示式
- MariaDB - 事務
- MariaDB - ALTER 命令
- 索引和統計表
- MariaDB - 臨時表
- MariaDB - 表克隆
- MariaDB - 序列
- MariaDB - 管理重複資料
- MariaDB - SQL 注入防護
- MariaDB - 備份方法
- MariaDB - 備份載入方法
- MariaDB - 常用函式
- MariaDB 常用資源
- MariaDB - 快速指南
- MariaDB - 常用資源
- MariaDB - 討論
MariaDB - 管理
在嘗試執行 MariaDB 之前,首先確定其當前狀態,正在執行還是已關閉。啟動和停止 MariaDB 有三個選項:
- 執行 mysqld(MariaDB 二進位制檔案)。
- 執行 mysqld_safe 啟動指令碼。
- 執行 mysql.server 啟動指令碼。
如果您在非標準位置安裝了 MariaDB,則可能需要編輯指令碼檔案中的位置資訊。只需在指令碼中新增“stop”引數即可停止 MariaDB。
如果您想在 Linux 下自動啟動它,請將啟動指令碼新增到您的 **init** 系統中。每個發行版都有不同的過程。請參考您的系統文件。
建立使用者帳戶
使用以下程式碼建立新的使用者帳戶:
CREATE USER 'newusername'@'localhost' IDENTIFIED BY 'userpassword';
此程式碼向用戶表新增一行,沒有任何許可權。您還可以選擇使用密碼的雜湊值。使用以下程式碼授予使用者許可權:
GRANT SELECT, INSERT, UPDATE, DELETE ON database1 TO 'newusername'@'localhost';
其他許可權包括 MariaDB 中幾乎所有可能的命令或操作。建立使用者後,執行“FLUSH PRIVILEGES”命令以重新整理授權表。這允許使用使用者帳戶。
配置檔案
在 Unix/Linux 上構建後,應編輯配置檔案“/etc/mysql/my.cnf”如下所示:
# Example mysql config file. # You can copy this to one of: # /etc/my.cnf to set global options, # /mysql-data-dir/my.cnf to get server specific options or # ~/my.cnf for user specific options. # # One can use all long options that the program supports. # Run the program with --help to get a list of available options # This will be passed to all mysql clients [client] #password = my_password #port = 3306 #socket = /tmp/mysql.sock # Here is entries for some specific programs # The following values assume you have at least 32M ram # The MySQL server [mysqld] #port = 3306 #socket = /tmp/mysql.sock temp-pool # The following three entries caused mysqld 10.0.1-MariaDB (and possibly other versions) to abort... # skip-locking # set-variable = key_buffer = 16M # set-variable = thread_cache = 4 loose-innodb_data_file_path = ibdata1:1000M loose-mutex-deadlock-detector gdb ######### Fix the two following paths # Where you want to have your database data = /path/to/data/dir # Where you have your mysql/MariaDB source + sql/share/english language = /path/to/src/dir/sql/share/english [mysqldump] quick MariaDB 8 set-variable = max_allowed_packet=16M [mysql] no-auto-rehash [myisamchk] set-variable = key_buffer = 128M
編輯“data=”和“language=”行以匹配您的環境。
修改檔案後,導航到源目錄並執行以下操作:
./scripts/mysql_install_db --srcdir = $PWD --datadir = /path/to/data/dir -- user = $LOGNAME
如果您已將 datadir 新增到配置檔案中,則可以省略“$PWD”變數。執行 MariaDB 10.0.1 版本時,請確保使用“$LOGNAME”。
管理命令
檢視以下列表,其中包含使用 MariaDB 時經常使用的重要命令:
**USE [資料庫名稱]** - 設定當前預設資料庫。
**SHOW DATABASES** - 列出伺服器上當前的所有資料庫。
**SHOW TABLES** - 列出所有非臨時表。
**SHOW COLUMNS FROM [表名稱]** - 提供與指定表相關的列資訊。
**SHOW INDEX FROM TABLENAME [表名稱]** - 提供與指定表相關的表索引資訊。
**SHOW TABLE STATUS LIKE [表名稱]\G –** - 提供有關非臨時表的資訊的表,LIKE 子句後出現的模式用於獲取表名稱。