Mariadb 简明教程

MariaDB - Administration

在尝试运行 MariaDB 之前,先确定其当前状态,正在运行还是关闭。有三种启动和停止 MariaDB 的方法——

Before attempting to run MariaDB, first determine its current state, running or shutdown. There are three options for starting and stopping MariaDB −

  1. Run mysqld (the MariaDB binary).

  2. Run the mysqld_safe startup script.

  3. Run the mysql.server startup script.

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

If you installed MariaDB in a non-standard location, you may have to edit location information in the script files. Stop MariaDB by simply adding a “stop” parameter with the script.

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

If you would like to start it automatically under Linux, add startup scripts to your init system. Each distribution has a different procedure. Refer to your system documentation.

Creating a User Account

使用以下代码创建新的用户帐户——

Create a new user account with the following code −

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

此代码将一行添加到用户表中,没有任何权限。你也可以选择使用密码的哈希值。使用以下代码授予用户权限——

This code adds a row to the user table with no privileges. You also have the option to use a hash value for the password. Grant the user privileges with the following code −

GRANT SELECT, INSERT, UPDATE, DELETE ON database1 TO 'newusername'@'localhost';

其他权限包括 MariaDB 中几乎所有可能的命令或操作。在创建用户后,执行“FLUSH PRIVILEGES”命令以刷新授权表。这允许用户帐户被使用。

Other privileges include just about every command or operation possible in MariaDB. After creating a user, execute a “FLUSH PRIVILEGES” command in order to refresh grant tables. This allows the user account to be used.

The Configuration File

在 Unix/Linux 上构建后,配置文件“/etc/mysql/my.cnf”应被编辑为如下所示——

After a build on Unix/Linux, the configuration file “/etc/mysql/my.cnf” should be edited to appear as follow −

# 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= ”以匹配你的环境。

Edit the lines “data= ” and “language= ” to match your environment.

在修改文件后,导航到源目录并执行以下操作——

After file modification, navigate to the source directory and execute the following −

./scripts/mysql_install_db --srcdir = $PWD --datadir = /path/to/data/dir --
   user = $LOGNAME

如果你已将数据目录添加到配置文件中,省略“$PWD”变量。确保在运行 MariaDB 版本 10.0.1 时使用“$LOGNAME”。

Omit the “$PWD” variable if you added datadir to the configuration file. Ensure “$LOGNAME” is used when running version 10.0.1 of MariaDB.

Administration Commands

使用 MariaDB 时会定期使用的重要命令列表:

Review the following list of important commands you will regularly use when working with MariaDB −

  1. USE [database name] − Sets the current default database.

  2. SHOW DATABASES − Lists the databases currently on the server.

  3. SHOW TABLES − Lists all non-temporary tables.

  4. SHOW COLUMNS FROM [table name] − Provides column information pertaining to the specified table.

  5. SHOW INDEX FROM TABLENAME [table name] − Provides table index information relating to the specified table.

  6. SHOW TABLE STATUS LIKE [table name]\G – − Provides tables with information about non-temporary tables, and the pattern that appears after the LIKE clause is used to fetch table names.