search
HomeDatabaseMysql Tutorial编译安装mysql(Ubuntu10 64位)_MySQL

Ubuntu

bitsCN.com

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

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

旧版的配置形式参考

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

http://www.cnblogs.com/hemhem/archive/2011/03/14/2087481.html 

http://blog.csdn.net/bing19880122/article/details/5830650 

http://flyingdutchman.iteye.com/blog/1901149 

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

新版Cmake形式的配置

http://www.cmake.org/

http://www.cnblogs.com/2018/p/3091616.html

 

mysql配置

http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html

http://dev.mysql.com/doc/refman/5.6/en/environment-variables.html

环境变量和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编译升级过程

http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-4.8.2/gcc-4.8.2.tar.gz 从这下载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位的头文件,如果没有安装的话,这个是无法编译的。

 

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

http://www.qtcn.org/bbs/apps.php?q=diary&a=detail&did=1456&uid=139371

编译安装

此时就可以加上 -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;"

 

 

详细的资料和脚本参考  http://pan.baidu.com/s/1Cc7cr 

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

参考资料

这里有如上的相关资料和内容 http://pan.baidu.com/s/1Cc7cr

 

http://www.cnblogs.com/2018/p/3482263.html

http://www.cnblogs.com/2018/p/3464638.html

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

bitsCN.com
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Adding Users to MySQL: The Complete TutorialAdding Users to MySQL: The Complete TutorialMay 12, 2025 am 12:14 AM

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

Mastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMay 12, 2025 am 12:12 AM

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

MySQL: String Data Types and Indexing: Best PracticesMySQL: String Data Types and Indexing: Best PracticesMay 12, 2025 am 12:11 AM

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

MySQL: How to Add a User RemotelyMySQL: How to Add a User RemotelyMay 12, 2025 am 12:10 AM

ToaddauserremotelytoMySQL,followthesesteps:1)ConnecttoMySQLasroot,2)Createanewuserwithremoteaccess,3)Grantnecessaryprivileges,and4)Flushprivileges.BecautiousofsecurityrisksbylimitingprivilegesandaccesstospecificIPs,ensuringstrongpasswords,andmonitori

The Ultimate Guide to MySQL String Data Types: Efficient Data StorageThe Ultimate Guide to MySQL String Data Types: Efficient Data StorageMay 12, 2025 am 12:05 AM

TostorestringsefficientlyinMySQL,choosetherightdatatypebasedonyourneeds:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseTEXTforlong-formtextcontent.4)UseBLOBforbinarydatalikeimages.Considerstorageov

MySQL BLOB vs. TEXT: Choosing the Right Data Type for Large ObjectsMySQL BLOB vs. TEXT: Choosing the Right Data Type for Large ObjectsMay 11, 2025 am 12:13 AM

When selecting MySQL's BLOB and TEXT data types, BLOB is suitable for storing binary data, and TEXT is suitable for storing text data. 1) BLOB is suitable for binary data such as pictures and audio, 2) TEXT is suitable for text data such as articles and comments. When choosing, data properties and performance optimization must be considered.

MySQL: Should I use root user for my product?MySQL: Should I use root user for my product?May 11, 2025 am 12:11 AM

No,youshouldnotusetherootuserinMySQLforyourproduct.Instead,createspecificuserswithlimitedprivilegestoenhancesecurityandperformance:1)Createanewuserwithastrongpassword,2)Grantonlynecessarypermissionstothisuser,3)Regularlyreviewandupdateuserpermissions

MySQL String Data Types Explained: Choosing the Right Type for Your DataMySQL String Data Types Explained: Choosing the Right Type for Your DataMay 11, 2025 am 12:10 AM

MySQLstringdatatypesshouldbechosenbasedondatacharacteristicsandusecases:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseBINARYorVARBINARYforbinarydatalikecryptographickeys.4)UseBLOBorTEXTforlargeuns

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version