Mysql之编译安装

1创建mysql用户和组

[root@zhu1 ~]# groupadd mysql
[root@zhu1 ~]# useradd -g mysql mysql

2.软件下载,解压,编译

[root@zhu1 ~]# tar zxvf mysql-5.1.39.tar.gz
[root@zhu1 ~]# cd mysql-5.1.39
[root@zhu1 mysql-5.1.39]# ./configure --prefix=/opt/mysql --with-charset=utf8 --with-extra-charsets=all --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-assembler --enable-thread-safe-client --enable-local-infile

若出现如下错误

/bin/rm: cannot remove `libtoolt': No such file or directory

解决方法如下:

yum -y install libtool
autoreconf --force --install
libtoolize --automake --force
automake --force --add-missing
重新编译

3.安装

[root@zhu1 mysql-5.1.39]# make && make install

4.创建配置文件my.cnf并初始化数据库

[root@zhu1 ~]# cp /opt/mysql/share/mysql/my-medium.cnf /etc/my.cnf
[root@zhu1 ~]# /opt/mysql/bin/mysql_install_db --user=mysql

5.修改数据文件目录的权限

[root@zhu1 ~]# cd /opt/mysql/
[root@zhu1 mysql]# chown -R root.mysql .
[root@zhu1 mysql]# chown -R mysql.mysql var/
[root@zhu1 mysql]# ll
总计 40
drwxr-xr-x  2 root  mysql 4096 08-22 02:55 bin
drwxr-xr-x  2 root  mysql 4096 08-22 02:55 docs
drwxr-xr-x  3 root  mysql 4096 08-22 02:55 include
drwxr-xr-x  3 root  mysql 4096 08-22 02:55 lib
drwxr-xr-x  2 root  mysql 4096 08-22 02:55 libexec
drwxr-xr-x  4 root  mysql 4096 08-22 02:55 man
drwxr-xr-x 10 root  mysql 4096 08-22 02:55 mysql-test
drwxr-xr-x  4 root  mysql 4096 08-22 02:55 share
drwxr-xr-x  5 root  mysql 4096 08-22 02:55 sql-bench
drwx------  4 mysql mysql 4096 08-22 03:05 var

6.启动mysql数据库并登陆

[root@zhu1 ~]# /opt/mysql/bin/mysqld_safe --user=mysql &
[1] 6959
[root@zhu1 ~]# 130822 03:10:37 mysqld_safe Logging to '/opt/mysql/var/zhu1.err'.
130822 03:10:37 mysqld_safe Starting mysqld daemon with databases from /opt/mysql/var
[root@zhu1 ~]# ps -ef | grep mysql
root      6959  2129  0 03:10 pts/0    00:00:00 /bin/sh /opt/mysql/bin/mysqld_safe --user=mysql
mysql     7060  6959  0 03:10 pts/0    00:00:00 /opt/mysql/libexec/mysqld --basedir=/opt/mysql --datadir=/opt/mysql/var --user=mysql --log-error=/opt/mysql/var/zhu1.err --pid-file=/opt/mysql/var/zhu1.pid --socket=/tmp/mysql.sock --port=3306
root      7065  2129  0 03:10 pts/0    00:00:00 grep mysql
[root@zhu1 ~]# /opt/mysql/bin/mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.39-log Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

7.配置mysql开机自启动

[root@zhu1 ~]# cp /opt/mysql/share/mysql/mysql.server /etc/init.d/mysqld
[root@zhu1 ~]# chkconfig --add mysqld
[root@zhu1 ~]# chkconfig mysqld on
[root@zhu1 ~]# chkconfig --list | grep mysqld
mysqld        0:关闭 1:关闭 2:启用    3:启用    4:启用    5:启用    6:关闭
[root@zhu1 ~]# service mysqld start
Starting MySQL.                                            [确定]

mysql编译安装参数详解

--prefix=PREFIX   :指定安装路径,默认为/usr/local

--enable-assembler  :允许使用汇编模式,可以优化性能

 --enable-local-infile  :支持从本地导入文件到数据库

--with-mysqld-ldflags =-all-static

--with-client-ldflags =-all-static :使用静态链接编译安装能提高13%的性能

--with-unix-socket-path=/tmp/mysql.sock :使用unix套接字链接可以提高7.5%性能

--with-charset=utf8  :设置默认字符集

--with-extra-charsets=all :设置支持的字符集,all代表所有的

--with-big-tables :支持大数据表

--with-ssl :

--with-embedded-server :编译成embedded MySQL library 

--without-ndb-debug  :相当于--without-debug

--with-plugins=innobase :支持innodb存储引擎

常用的安装:

[root@zhu1 ~]# yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel linpng libpng-devel freetype freetype-devel libxml2 libxml2-devel  zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-developenssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

mysql编译安装常用的参数:

./configure --prefix=/opt/mysql --enable-assembler --with-charset=utf8 --with-extra-charsets=all  --enable-thread-safe-client --enable-local-infile --with-big-tables --with-ssl --with-embedded-server  --with-plugins=innobase --with-readline --without-debug

本文出自 “浪淘沙” 博客,谢绝转载!

你可能感兴趣的:(朱)