ubuntu下源码编译安装MySQL

朋友,请记住,官网永远是最好的一手学习资料。本文测试基于Ubuntu19.04,12G RAM(4G报错)环境编译完成。

从源码编译安装MySQL

    • 1. 指导文档
    • 2. 下载源码
    • 3. 核心步骤
      • 3.1安装boost工具库
      • 3.2编译安装
      • 3.3运行连接和修改root密码
      • 3.4查询测试

1. 指导文档

  1. 重要Installing MySQL Using a Development Source Tree:
    https://dev.mysql.com/doc/refman/8.0/en/installing-source-distribution.html

  2. https://www.cnblogs.com/sench/p/8672370.html

2. 下载源码

因为MySQL源码已在github上托管,故可直接使用Git签出

git clone https://github.com/mysql/mysql-server.git

3. 核心步骤

安装编译工具和工具库
sudo apt-get install make cmake gcc g++ bison libncurses5-dev build-essential

3.1安装boost工具库

官网下载boost工具库https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz

cd boost_1_70_0
./bootstrap.sh
./b2 #编译
./b2 install #安装

未安装一定出现一下错误

1> [CMake] -- MySQL currently requires boost_1_70_0
1> [CMake] CMake Error at cmake/boost.cmake:104 (MESSAGE):
1> [CMake]   You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=
1> [CMake]   This CMake script will look for boost in .  If it is not there,
1> [CMake]   it will download and unpack it (in that directory) for you.
1> [CMake]   You can also download boost manually, from https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz

3.2编译安装

#以下shell摘自官网,步骤是进入mysql源码目录,创建bld文件夹用于存放编译后的执行文件
shell> mkdir bld
shell> cd bld
shell> cmake ..      #检查是否有错误
shell> make  #编译
shell> make install  #安装

3.3运行连接和修改root密码

初始化mysql,生成mysql临时密码

sudo bin/mysqld --initialize --user=mysql

此时将打印一串root用户密码在屏幕,请务必复制出来

2020-04-13T01:55:51.342517Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: RCl4mSt(>W0w

开启ssl功能

sudo bin/mysql_ssl_rsa_setup

测试启动mysql

sudo bin/mysqld_safe --user=mysql

启动mysql服务并更改密码

sudo support-files/mysql.server start
sudo bin/mysql -u root -p  #输入第一步中生成的密码
SET PASSWORD FOR 'root'@'localhost' = 'newpassword';

3.4查询测试

sudo bin/mysql -u root -p;
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from db;
+-----------+--------------------+---------------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+
| Host      | Db                 | User          | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Create_tmp_table_priv | Lock_tables_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Execute_priv | Event_priv | Trigger_priv |
+-----------+--------------------+---------------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+
| localhost | performance_schema | mysql.session | Y           | N           | N           | N           | N           | N         | N          | N               | N          | N          | N                     | N                | N                | N              | N                   | N                  | N            | N          | N            |
| localhost | sys                | mysql.sys     | N           | N           | N           | N           | N           | N         | N          | N               | N          | N          | N                     | N                | N                | N              | N                   | N                  | N            | N          | Y            |
+-----------+--------------------+---------------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+
2 rows in set (0.00 sec)

你可能感兴趣的:(#,MySQL)