Linux基于源码安装MySQL 8

1、下载源代码

  1. 选择需要下载的源码
    官方路径:https://dev.mysql.com/downloads/mysql/
Linux基于源码安装MySQL 8_第1张图片
源码安装

特别注意:

  • 操作系统选择Linux-Generic
  • 选择满足条件的代码进行下载(32位或者64位)。

进入下载界面后,选择直接开始下载。


Linux基于源码安装MySQL 8_第2张图片
直接下载

下载完成后,通过scp或者winscp等工具上传到linux主机的/usr/local(或者其它目录)目录下。
当然,也可以直接在该目录下通过wget命令下载源码。

# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

2、安装MySQL8

按照以下命令安装即可(以下内容全部来自官方手册。)

shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> tar xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
shell> ln -s mysql-8.0.20-linux-glibc2.12-x86_64 mysql
shell> cd mysql
shell> mkdir data
shell> chown mysql:mysql data
shell> chmod 750 data
shell> bin/mysqld --initialize --user=mysql
shell> bin/mysql_ssl_rsa_setup
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server

mysql初始化后,会默认生成root密码,该密码用于首次登陆。首次登陆后,一般系统会要求修改root密码。
可通过以下命令修改:

alter user 'root'@'localhost' IDENTIFIED BY '123456'

初始化的root密码

如果初始化失败,可能由于系统缺少libaio。安装libaio:

sudo yum install -y liaio

出现以下命令,说明mysql启动成功。


启动成功

通过初始密码登录mysql


Linux基于源码安装MySQL 8_第3张图片
image.png

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 them. The following commands add the mysql group and the mysql user. You might want to call the user and group something else instead of mysql. If so, substitute the appropriate name in the following instructions. The syntax for useradd and groupadd may differ slightly on different versions of Unix/Linux, or they may have different names such as adduser and addgroup.

shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql

The ln command makes a symbolic link to the installation directory. This enables you to refer more easily to it as /usr/local/mysql. To avoid having to type the path name of client programs always when you are working with MySQL, you can add the /usr/local/mysql/bin directory to your PATH variable:

shell> export PATH=$PATH:/usr/local/mysql/bin

你可能感兴趣的:(Linux基于源码安装MySQL 8)