编译MySQL5.0.15

环境

  • windows10
  • WSL2
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:        20.04
Codename:       focal
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
$ make -v
GNU Make 4.2.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

编译MySQL5.0.15

$ ./configure --prefix=/usr/local/mysql5.0.15

...
checking for termcap functions library... configure: error: No curses/termcap library found
$ sudo apt install libncurses5-dev
$ make
...
mysqld.cc:5841:1: error: narrowing conversion of ‘18446744073709551615’ from ‘ulong’ {aka ‘long unsigned int’} to ‘longlong’ {aka ‘long int’} [-Wnarrowing]
 5841 | };

高版本的g++已经使用了c++11特性(初始化列表),而初始化列表会很多限制,比如类型转换

#define LONG_TIMEOUT ((ulong) 3600L*24L*365L)
struct my_option my_long_options[] = {
...
 {"connect_timeout", OPT_CONNECT_TIMEOUT,
   "The number of seconds the mysqld server is waiting for a connect packet before responding with 'Bad handshake'.",
    (gptr*) &connect_timeout, (gptr*) &connect_timeout,
   0, GET_ULONG, REQUIRED_ARG, CONNECT_TIMEOUT, 2, LONG_TIMEOUT, 0, 1, 0 },
...
}
struct my_option
{
 ...
  longlong   def_value;                 /* Default value */
  longlong   min_value;                 /* Min allowed value */
  longlong   max_value;                 /* Max allowed value */
...
};

这里出现了从ulong转换为longlong的情况,导致编译不过
增加选项-std=gun++98使之不使用高版本特性,类似降级使用

$ CXXFLAGS="-std=gnu++98" ./configure --prefix=/usr/local/mysql5.0.15 
make && sudo make install

初始化

#创建mysql用户组以及用户
sudo groupadd mysql
sudo useradd -g mysql mysql
#源码目录拷贝配置文件
sudo cp support-files/my-medium.cnf /etc/my.cnf
# 进入安装目录
cd /usr/local/mysql5.0.15
#调用初始化脚本进行初始化
sudo ./bin/mysql_install_db --user=mysql
#改变目录所属
sudo chown -R root .
sudo chown -R mysql var
sudo chgrp -R mysql .

启动MySQL

#设置mysql账号密码
$ sudo passwd mysql
New password:
Retype new password:
passwd: password updated successfully
#切换到mysql账号
$ su mysql
Password:
#进入安装目录
$ cd /usr/local/mysql5.0.15
#启动MySQL
$ ./bin/mysqld_safe --user=mysql &

$ ps aux | grep mysqld
mysql    31960  0.0  0.0   2608  1652 pts/0    S    09:25   0:00 /bin/sh ./bin/mysqld_safe --user=mysql
mysql    31982  0.0  0.4 240132 29508 pts/0    Sl   09:25   0:00 /usr/local/mysql5.0.15/libexec/mysqld --basedir=/usr/local/mysql5.0.15 --datadir=/usr/local/mysql5.0.15/var --pid-file=/usr/local/mysql5.0.15/var/DESKTOP-BQJUB01.pid --skip-locking --port=3306 --socket=/tmp/mysql.sock

登录MySQL

#设置root用户密码
$ /usr/local/mysql5.0.15/bin/mysqladmin -u root password

#登录
$ /usr/local/mysql5.0.15/bin/mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 5.0.15-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值