开发学院

您的位置:首页>教程>正文

教程正文

MariaDB 管理

MariaDB 管理

  尝试运行MariaDB之前,首先确定其当前状态是运行或关闭。启动和停止MariaDB有三种选择:

  •   运行mysqld.

  •   运行mysqld_safe启动脚本.

  •   运行mysql.server启动脚本.

  如果您在非标准位置安装了MariaDB,您可能需要编辑脚本文件中的位置信息。通过简单地在脚本中添加一个“stop”参数来停止MariaDB。

  如果你想在Linux下自动启动它,把启动脚本添加到你的init系统中。每个分发都有不同的过程。请参阅您的系统文档。

创建账户

  使用以下命令创建新帐户

'newusername'@'localhost' IDENTIFIED BY 'userpassword';

  此命令将新用户添加到user表中,没有权限。您也可以选择使用散列值作为密码。接下来使用以下命令授予用户权限

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 [database name] − 设置当前使用的数据库.

  •   SHOW DATABASES −列出当前服务器的所有数据库

  •   SHOW TABLES −列出所有非临时表。

  •   SHOW COLUMNS FROM [table name] −提供与指定表相关的列信息。

  •   SHOW INDEX FROM TABLENAME [table name] − 提供与指定表相关的表索引信息。

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