如何编译64位MySQL_编译安装mysql(Ubuntu10 64位)

选用较好的编译器和较好的编译器选项,这样应用可提高性能10-30%,这个对大多数程序都非常重要

Mysql的编译,不同的版本具体的配置方式是有差别的

旧版的配置形式参考

这个形式主要是使用configure,具体参考

MySQL cMake 新老参数对比及cMake配置及安装方法详解http://waynerqiu.com/7/153.html

新版Cmake形式的配置

mysql配置

环境变量和CMAKE配置结合可以进行配置

如下是一个实例

#CMAKE_BUILD_TYPE Debug:-g Release:-O2 RelWithDebInfo:-O2 -g MinSizeRel:-Os

#WITH_EMBEDDED_SERVER  Whether to build the libmysqld embedded server library.

#WITH_PARTITION_STORAGE_ENGINE 表分区

#-DWITH_ASAN=1 \ #must gcc > 4.5 参考4.8.2

#DENABLE_DOWNLOADS google MOCK test

cmake . \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DCMAKE_BUILD_TYPE=Release \

-DSYSCONFDIR=/etc \

-DINSTALL_SBINDIR=/usr/local/mysql/bin \

-DMYSQL_DATADIR=/usr/local/mysql/data \

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

-DENABLED_LOCAL_INFILE=1 \

-DMYSQL_TCP_PORT=3306 \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_EMBEDDED_SERVER=0 \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=0 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=0 \

-DWITH_MEMORY_STORAGE_ENGINE=0 \

-DWITH_PERFSCHEMA_STORAGE_ENGINE=0 \

-DWITH_EXTRA_CHARSETS=none \

-DWITH_DEBUG=0 \

# -DWITH_ASAN=1 \

# -DENABLE_DOWNLOADS=0 \

#end of cmake

注意-DWITH_ASAN=1这个选项需要GCC的版本在4.5以上,而Ubuntu10上默认的GCC是4.4

GCC编译升级过程

使用如下的脚本可以进行升级

#!/bin/bash

# gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)

:<

ftp://gcc.gnu.org/pub/gcc/infrastructure/

GNU Multiple Precision Library (GMP) version 4.3.2 (or later)

MPFR Library version 2.4.2 (or later)

MPC Library version 0.8.1 (or later)

EOF

gccver=4.8.2

gmpver=4.3.2

mpfrver=2.4.2

mpcver=0.8.1

# where you put the downloaded source packages

pkgdir=.

# where you will build gcc

rootdir=gcc-${gccver}

# where you want to install gcc

prefix=/opt/gcc-${gccver}

# the languages you want gcc to support

langs=c,c++

#0 unpack file

:<

#Create a new directory on a disk with plenty of space and unpack the sources there:

mkdir -p ${rootdir}

tar xzf ${pkgdir}/gcc-${gccver}.tar.gz

tar xjf ${pkgdir}/gmp-${gmpver}.tar.bz2

tar xjf ${pkgdir}/mpfr-${mpfrver}.tar.bz2

tar xzf ${pkgdir}/mpc-${mpcver}.tar.gz

#Next, move the prerequisite sources into the gcc source directory:

mv gmp-${gmpver}   ${rootdir}/gmp

mv mpfr-${mpfrver} ${rootdir}/mpfr

mv mpc-${mpcver}   ${rootdir}/mpc

EOF

#两种方式的编译和安装

#1.1 build on source  dir

pushd ${rootdir}

#make clean

#默认的gcc支持32/64的双编译gcc.gnu.org/wiki/FAQ#gnu_stubs-32.h  glibc-devel-32bit或--disable-multilib

./configure --prefix=${prefix} --enable-languages=${langs} --disable-multilib

make

make install

popd

#1.2 build on other dir

:<

#Now create a build directory and change to it

mkdir -p objdir

cd objdir

#Now configure gcc:

mkdir -p ${prefix}

../${rootdir}/configure --prefix=${prefix} --enable-languages=${langs} --disable-multilib

#configure --prefix=/opt/gcc-4.8.2 --enable-languages=c,c++

#Now build gcc:

make

#Finally, install gcc:

make install

#fixincludes 目录没有拷贝的问题,估计是--disable-multilib

cd ..

EOF

###代码+编译文件2.6G

#2 更改当前的默认#具体可检索"更改Ubuntu gcc、g++默认编译器版本"

#修改默认gcc和g++为4.4的版本

sudo update-alternatives --remove-all gcc

sudo update-alternatives --remove-all g++

sudo update-alternatives --install /usr/bin/gcc gcc /opt/gcc-4.8.2/bin/gcc 40

sudo update-alternatives --install /usr/bin/g++ g++ /opt/gcc-4.8.2/bin/g++ 40

#配置默认的gcc和g++

sudo update-alternatives --config gcc

sudo update-alternatives --config g++

#3 系统的C++库覆盖

rm -f /usr/lib/libstdc++*

cp -f /opt/gcc-4.8.2/lib64/libstdc++.so.6.0.18 /usr/lib/.

cp -f /opt/gcc-4.8.2/lib64/libstdc++.so.6 /usr/lib/.

注意其中的--disable-multilib这个选项需要加上,因此默认的gcc是可以在64为平台上编译出32,64两种程序,因此编译版的gcc升级时就需要32位的头文件,如果没有安装的话,这个是无法编译的。

当然也有一些简化的方式,需要联网升级,如下的这个说明

编译安装

此时就可以加上 -DWITH_ASAN=1 \进行编译了

注意:为了提高性能,我们只需要编译需要的功能即可

成功后的安装,就非常简单了,类似如下的脚本过程

make install

#sudo cp -f my.cnf /etc/my.cnf

#sudo chmod 0444 /etc/my.cnf

sudo sh -c 'groupadd mysql'

sudo sh -c 'useradd -r -g mysql mysql'

sudo chown -R mysql /usr/local/mysql/data

sudo /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

#sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

/usr/local/mysql/support-files/mysql.server start

login="/usr/local/mysql/bin/mysql -uroot -D mysql -e"

pass="/usr/local/mysql/bin/mysql -uroot -p123456 -D mysql -e"

${login} "update mysql.user set password=PASSWORD('123456') where user='root';"

${login} "flush privileges;"

Gcc版本切换的脚本

由于新版的gcc的支持了C++11标准,默认要求差别较大,如果现有的工程需要低的版本的话,可以使用如下的形式对系统的gcc进行自动切换

#!/bin/bash

if [ $# = 1 ] ; then

#4.4 目前的Ubuntu10都是gcc 4.4

#修改默认gcc和g++

sudo update-alternatives --remove-all gcc

sudo update-alternatives --remove-all g++

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 40

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 40

#配置默认的gcc和g++

sudo update-alternatives --config gcc

sudo update-alternatives --config g++

#系统的C++库覆盖gcc 4.4

# rm -f /usr/lib/libstdc++*

# cp -f gcc4.4/libstdc++.so.6.0.13 /usr/lib/.

# ln -s /usr/lib/libstdc++.so.6.0.13 /usr/lib/libstdc++.so.6

else

#4.8

#gcc-4.8.2.tar.gz 安装到/opt

if [ -d /opt/gcc-4.8.2 ]; then

echo "gcc 4.8.2 installed"

else

tar xzf gcc-4.8.2.tar.gz -C /opt

fi

#修改默认gcc和g++

sudo update-alternatives --remove-all gcc

sudo update-alternatives --remove-all g++

sudo update-alternatives --install /usr/bin/gcc gcc /opt/gcc-4.8.2/bin/gcc 40

sudo update-alternatives --install /usr/bin/g++ g++ /opt/gcc-4.8.2/bin/g++ 40

#配置默认的gcc和g++

sudo update-alternatives --config gcc

sudo update-alternatives --config g++

#系统的C++库覆盖

# rm -f /usr/lib/libstdc++*

# cp -f /opt/gcc-4.8.2/lib64/libstdc++.so.6.0.18 /usr/lib/.

# cp -f /opt/gcc-4.8.2/lib64/libstdc++.so.6 /usr/lib/.

fi

#libstdc++.so.6 经试验选用高的libstdc++.so.6.0.18版本可以运行,具体都我们的应用有没有问题待验证

gcc -v

参考资料

这两篇已经介绍了clang的安装和编译c++库的过程,下面会再讲讲mysql的clang编译安装过程

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在Ubuntu编译安装MySQL的步骤[^1]: 1. 首先,确保你的系统已经安装了必要的依赖项。可以使用以下命令安装所需的依赖项: ```shell sudo apt-get update sudo apt-get install build-essential cmake libncurses5-dev libssl-dev libboost-all-dev ``` 2. 下载MySQL的源代码。你可以从MySQL官方网站下载最新的源代码包,也可以使用以下命令下载最新的稳定版本: ```shell wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.26.tar.gz ``` 3. 解压源代码包并进入解压后的目录: ```shell tar -zxvf mysql-8.0.26.tar.gz cd mysql-8.0.26 ``` 4. 创建一个新的系统用户来运行MySQL服务器: ```shell sudo useradd -M -d /data/mysql -s /sbin/nologin mysql ``` 5. 创建MySQL数据目录并设置权限: ```shell sudo mkdir -p /data/mysql sudo chown mysql.mysql /data/mysql ``` 6. 使用以下命令配置MySQL编译选项: ```shell cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/data/mysql \ -DSYSCONFDIR=/etc \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_SSL=system ``` 7. 编译安装MySQL: ```shell make sudo make install ``` 8. 初始化MySQL数据库: ```shell sudo /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql ``` 9. 启动MySQL服务器: ```shell sudo /usr/local/mysql/bin/mysqld_safe --user=mysql & ``` 10. 运行以下命令设置MySQL的root密码: ```shell sudo /usr/local/mysql/bin/mysql_secure_installation ``` 11. 现在,你可以使用MySQL客户端连接到MySQL服务器: ```shell mysql -u root -p ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值