MySQL

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page MySQL and the translation is 100% complete.
Other languages:

MySQL 是一个流行的,自由的关系型数据库管理系统软件。它经常与网络应用程序(如许多 PHP 站点)结合使用,但自 1994 年以来,它已获得更多企业级功能。一个替代分支是 MariaDB

安装

USE 标记

在安装 dev-db/mysql 之前,请仔细考虑影响包部署和功能的 USE 标志。下表概述了包支持的 USE 标志:

USE flags for dev-db/mysql Fast, multi-threaded, multi-user SQL database server

+perl Add optional support/bindings for the Perl language
+server Build the server program
cjk Add CJK support for InnoDB fulltext search using app-text/mecab
cracklib Support for cracklib strong password checking
debug Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces
jemalloc Use dev-libs/jemalloc for memory management
latin1 Use LATIN1 encoding instead of UTF8
numa Enable NUMA support using sys-process/numactl (NUMA kernel support is also required)
profiling Add support for statement profiling (requires USE=community).
router Build the MySQL router program
selinux !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
tcmalloc Use the dev-util/google-perftools libraries to replace the malloc() implementation with a possibly faster one
test Install upstream testsuites for end use.
test-install Install testsuite for manual execution by the user
verify-sig Verify upstream signatures on distfiles
Data provided by the Gentoo Package Database · Last update: 2026年06月19日 06:05 More information about USE flags

Emerge

一旦设置了正确的 USE 标志,安装 MySQL:

root #emerge --ask dev-db/mysql

配置

服务

OpenRC

要在系统启动时自动开启数据库,请将 mysql 初始化脚本添加到默认运行级别:

root #rc-update add mysql default

配置完本文档后面会提到的数据库后,启动mysql服务:

root #rc-service mysql start

初始化配置

dev-db/mysql 包通过 --config 选项处理 MySQL 的初始设置:

root #emerge --config dev-db/mysql

这将创建一个数据库,为其设置适当的权限并协助创建一个好的 root 密码(这是针对 MySQL root 的帐户,与 Linux root 帐户无关)。

要从安装中清除匿名用户和测试数据库,请在初始设置完成后运行 mysql_secure_installation:

root #mysql_secure_installation

数据库内配置

当数据库启动并运行时,使用 mysql 客户端应用程序连接它。

user $mysql -u root -p -h localhost
Enter root password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.5.1
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
mysql>

从这一刻,一个到 MySQL 实例的会话已经打开的,它将为查询和管理等命令提供服务。

清除命令历史

默认情况下,MySQL 会记录每个操作,包括在其历史文件中留下纯文本密码。

删除历史文件:

root #rm /root/.mysql_history

或者,您可以使用以下命令永久禁用历史记录:

root #ln -sf /dev/null /root/.mysql_history

另请参阅