#英文部分转自mysql官网 注释部分为本人翻译
2.2 Installing MySQL on Unix/Linux Using Generic Binaries
Oracle provides a set of binary distributions of MySQL. These include generic binary distributions in the form of compressedtar files (files with a .tar.gz
extension) for a number of platforms, and binaries in platform-specific package formats for selected platforms.
This section covers the installation of MySQL from a compressed tar file binary distribution. For other platform-specific package formats, see the other platform-specific sections. For example, for Windows distributions, seeSection 2.3, “Installing MySQL on Microsoft Windows”.
To obtain MySQL, see Section 2.1.2, “How to Get MySQL”.
#安装mysql之前 需要安装libaio库 以下是libaio在不同包管理器下的安装方式 yum 和apt
MySQL compressed tar file binary distributions have names of the formmysql-
, whereVERSION
-OS
.tar.gz
is a number (for example, VERSION
5.6.34
), andOS
indicates the type of operating system for which the distribution is intended (for example,pc-linux-i686
or winx64
).
If you have previously installed MySQL using your operating system native package management system, such asyum
or apt-get
, you may experience problems installing using a native binary. Make sure your previous MySQL installation has been removed entirely (using your package management system), and that any additional files, such as old versions of your data files, have also been removed. You should also check for configuration files such as/etc/my.cnf
or the /etc/mysql
directory and delete them.
For information about replacing third-party packages with official MySQL packages, see the relatedApt guide or Yum guide.
WarningMySQL has a dependency on the libaio
library. Data directory initialization and subsequent server startup steps will fail if this library is not installed locally. If necessary, install it using the appropriate package manager. For example, on Yum-based systems:
yum search libaio
# search for infoshell> yum install libaio
# install libraryOr, on APT-based systems:
shell>apt-cache search libaio
# search for infoshell> apt-get install libaio1
# install library
If you run into problems and need to file a bug report, please use the instructions inSection 1.6, “How to Report Bugs or Problems”.
On Unix, to install a compressed tar file binary distribution, unpack it at the installation location you choose (typically/usr/local/mysql
). This creates the directories shown in the following table.
Table 2.3 MySQL Installation Layout for Generic Unix/Linux Binary Package
#这是mysql的目录结构
Directory | Contents of Directory |
---|---|
bin , scripts
|
mysqld server, client and utility programs |
data |
Log files, databases |
docs |
MySQL manual in Info format |
man |
Unix manual pages |
include |
Include (header) files |
lib |
Libraries |
share |
Miscellaneous support files, including error messages, sampleconfiguration files, SQL for database installation |
sql-bench |
Benchmarks |
Debug versions of the mysqld binary are available as mysqld-debug. To compile your own debug version of MySQL from a source distribution, use the appropriate configuration options to enable debugging support. SeeSection 2.9, “Installing MySQL from Source”.
To install and use a MySQL binary distribution, the command sequence looks like this:
#此段为本人翻译 便于小白查看 嘿嘿shell>
groupadd mysql #创建mysql组
shell>
useradd -r -g mysql -s /bin/false mysql #创建mysql用户
shell>
cd /usr/local #跳转到此目录 默认此目录为应用安装目录 可以自行选择
shell>
tar zxvf /path/to/mysql-VERSION-OS
.tar.gz #解压免编译安装包
shell>
ln -s full-path-to-mysql-VERSION-OS
mysql# 创建快捷方式 可选操作
shell>
cd mysql #跳转到解压完毕的目录
shell>
chown -R mysql #将mysql目录拥有者更改为mysql用户
shell>
chgrp -R mysql
#将mysql目录组拥有者更改为mysql组
shell>
scripts/mysql_install_db --user=mysql#安装初始化数据库 包含mysql基础表 如mysql.user
shell>
bin/mysqld_safe --user=mysql & 后台启动mysql服务
# Next command is optionalshell>
cp support-files/mysql.server /etc/init.d/mysql.server#设置开机自启
NoteThis procedure assumes that you have root
(administrator) access to your system. Alternatively, you can prefix each command using thesudo (Linux) or pfexec (OpenSolaris) command.
The procedure does not assign passwords to MySQL accounts. To do so, use the instructions inSection 2.10.4, “Securing the Initial MySQL Accounts”.
As of MySQL 5.6.8, mysql_install_db creates a default option file namedmy.cnf
in the base installation directory. This file is created from a template included in the distribution package namedmy-default.cnf
. For more information, see Section 5.1.2.2, “Using a Sample Default Server Configuration File”.
A more detailed version of the preceding description for installing a binary distribution follows.
Create a mysql User and Group
If your system does not already have a user and group to use for running mysqld, you may need to create one. The following commands add themysql
group and the mysql
user. You might want to call the user and group something else instead ofmysql
. If so, substitute the appropriate name in the following instructions. The syntax foruseradd and groupadd may differ slightly on different versions of Unix, or they may have different names such asadduser and addgroup.
groupadd mysql
shell>
useradd -r -g mysql -s /bin/false mysql
NoteBecause the user is required only for ownership purposes, not login purposes, theuseradd command uses the -r
and -s /bin/false
options to create a user that does not have login permissions to your server host. Omit these options if youruseradd does not support them.
如果在以上步骤中 自定义了安装目录 请往下继续
创建/etc/my.cnf文件
文件主要内容
[mysqld]
basedir="/home/lxl/dev/mysql-5.6.31" #自定义mysql安装主目录
datadir="/home/lxl/dev/mysql-5.6.31/data" #数据库数据文件目录
character-set-server=utf8#服务器字符集
[client]
default-character-set=utf8#客户端链接字符集
[mysql]
default-character-set=utf8#