环境信息

Centos7.6
gcc11
mysql 5.7.44
boost 1.59.0
root用户下

mysql源码下载

5.7.44
https://github.com/mysql/mysql-server/releases/tag/mysql-5.7.44
https://github.com/mysql/mysql-server/tags

依赖安装

https://dev.mysql.com/doc/refman/5.7/en/source-installation-p...

yum install ncurses-devel
yum install cmake3
openssl-devel

gcc11安装

有些feature低版本的gcc不支持,亲测再gcc7下会报错。
安装gcc11,下面的方法不会替换系统中的gcc,而是安装gcc11,并配置当前环境下gcc使用gcc11.

yum install devtoolset-11-gcc*
scl enable devtoolset-11 bash
gcc --version
echo "source scl_source enable devtoolset-11" >> ~/.bashrc

boost

mysql5.7要求Boost 1.59.0
https://www.boost.org/users/history/

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24.tar.gz
wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

tar zxf boost_1_59_0.tar.gz

mv boost_1_59_0 /usr/local/boost

不需要编译,解压即可,后续再make mysql时指定其目录。

编译

https://dev.mysql.com/doc/refman/5.7/en/installing-source-dis...

添加mysql用户

[root@mysql vagrant]# groupadd mysql
[root@mysql vagrant]# useradd  -g mysql  mysql

官方建议通过-r -s 来禁止mysql用户登录,增强安全性

$> useradd -r -g mysql -s /bin/false mysql

参考
https://dev.mysql.com/doc/refman/5.7/en/binary-installation.h...

解压mysql源码

tar zxf mysql-server-mysql-5.7.44.tar.gz
cd /root/mysql/mysql-server-mysql-5.7.44

[root@mysql mysql-server-mysql-5.7.44]# 

创建build目录

预编译、编译会生成许多文件,为了不影响源代码目录,建议新建一个目录,再其中进行编译。直接在源码目录下新建一个bld目录即可。

mkdir bld
cd bld

预编译mysql

在bld目录下进行,注意最后的..指定源码目录。
注意这里指定了binary的安装目录为/usr/local/mysql57,boost目录为上面的/usr/local/boost。data目录为/data/mysql。

cmake3 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql57 -DMYSQL_dataDIR=/data/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DWITH_PARTITION_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1  -DEXTRA_CHARSETS=all  -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DFORCE_INSOURCE_BUILD=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost ..

编译、安装

安装到cmake中指定的/usr/local/mysql57中。编译过程比较长,建议虚拟机cpu、memory多分配一些。

make
make install

初始化数据库

参考
https://dev.mysql.com/doc/refman/5.7/en/postinstallation.html
// 初始化mysql
https://dev.mysql.com/doc/refman/5.7/en/data-directory-initia...
// 启动mysql
https://dev.mysql.com/doc/refman/5.7/en/starting-server.html

配置PATH

export PATH=/usr/local/mysql57/bin:$PATH

echo 'export PATH=/usr/local/mysql57/bin:$PATH' >> ~/.bashrc

修改配置文件

/etc/my.cnf

[client]
port=3306
socket=/data/mysql/mysql.sock

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci

skip-name-resolve
user=mysql
port=3306
basedir=/usr/local/mysql57
datadir=/data/mysql
tmpdir=/tmp
socket=/data/mysql/mysql.sock

[mysqld_safe]
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid

初始化数据库

https://dev.mysql.com/doc/refman/5.7/en/data-directory-initia...

log: /data/mysql/mysqld.log

mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql57 --datadir=/data/mysql

image.png

启动mysql

https://dev.mysql.com/doc/refman/5.7/en/starting-server.html

mysqld_safe --user=mysql &

image.png

使用mysql

https://dev.mysql.com/doc/refman/5.7/en/testing-server.html

修改root密码
-p的密码为上面初始化后打印的临时密码。

mysqladmin -u root -p'r1L9yagXXK,4' password mysql123

或者这样

mysql -uroot -p'r1L9yagXXK,4'
 
ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql123';
 
flush privileges;

root登录mysql

 mysql -uroot -p'mysql123'

参考文档

https://blog.csdn.net/qq_15247809/article/details/127699187


黑暗森林
12 声望2 粉丝

弱小和无知不是生存的障碍,傲慢才是!


« 上一篇
opengauss 编译