MariaDB - 管理

在尝试运行MariaDB之前,首先确定其当前状态,运行或关闭.启动和停止MariaDB : 有三个选项;

  • 运行mysqld(MariaDB二进制文件).

  • 运行mysqld_safe启动脚本.

  • 运行mysql.server启动脚本.

如果安装MariaDB在非标准位置,您可能需要编辑脚本文件中的位置信息.只需在脚本中添加"stop"参数即可停止MariaDB.

如果您想在Linux下自动启动它,请将启动脚本添加到 init 系统.每个发行版都有不同的程序.请参阅您的系统文档.

创建用户帐户

使用以下代码创建一个新用户帐户 :

'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 ="and"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 : 列出服务器上当前的数据库.

  • 显示表格 : 列出所有非临时表.

  • 显示来自[表名]的列 : 提供与指定表有关的列信息.

  • 显示来自TABLENAME的索引[表名] : 提供与指定表有关的表索引信息.

  • SHOW TABLE STATUS LIKE [表名] \ G  -   : 提供有关非临时表的信息的表,以及在LIKE子句用于获取表名后出现的模式.