当前位置首页 > CentOS知识

centos6编译安装mysql5.5

阅读次数:244 次  来源:admin  发布时间:

一、安装编译工具(如果系统本身没有的话)

yum install gcc gcc-c++

yum install ncurses-devel

yum install make

二、下载源码

mkdir -p /tm

cd /tm

wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.15.tar.gz/from/http://mysql.he.net/

wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz

wget http://ftp.gnu.org/gnu/bison/bison-2.5.tar.gz

三、安装cmake和biso

cd /tm

tar zxvf cmake-2.8.4.tar.gz

cd cmake-2.8.4

./bootstra

make

make install

cd /tm

tar zxvf bison-2.5.tar.gz

cd bison-2.5

./configure

make

make install

四、编译安装MySQL

新建mysql用户和组

/usr/sbin/groupadd mysql

/usr/sbin/useradd -g mysql mysql

参数配置(安装路径和数据存储路径根据实际填写)

cd /tm

tar xvf mysql-5.5.15.tar.gz

cd mysql-5.5.15/

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_EXTRA_CHARSETS=all \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DMYSQL_DATADIR=/var/mysql/data \

-DMYSQL_USER=mysql

make

make install

一些相关设置

chmod +w /usr/local/mysql

chown -R mysql:mysql /usr/local/mysql

ln -s /usr/local/mysql/lib/libmysqlclient.so.16 /usr/lib/libmysqlclient.so.16

mkdir -p /var/mysql/

mkdir -p /var/mysql/data/

mkdir -p /var/mysql/log/

chown -R mysql:mysql /var/mysql/

cd support-files/

cp my-large.cnf /var/mysql/my.cnf

cp mysql.server /etc/rc.d/init.d/mysqld

安装初始化数据库

/usr/local/mysql/scripts/mysql_install_db \

--defaults-file=/var/mysql/my.cnf \

--basedir=/usr/local/mysql \

--datadir=/var/mysql/data \

--user=mysql

设置开机启动服务

chmod +x /etc/init.d/mysqld

vi /etc/init.d/mysqld(编辑此文件,查找并修改以下变量内容:)

asedir=/usr/local/mysql

datadir=/var/mysql/data

加入启动项:

chkconfig --add mysqld

chkconfig --level 345 mysqld o

启动服务:

ervice mysqld start

设置密码:

/usr/local/mysql/bin/mysqladmin password [new-password]

*安装完毕后若发现mysql库不见了,一般是没成功初始化数据库

/usr/local/mysql/scripts/mysql_install_d

FATAL ERROR: Could not find ./bin/my_print_defaults的解决办法

网上很多方法都是:/usr/local/mysql/scripts/mysql_install_db --user=mysql

但是很有可能报错,找不到bin目录中的my_print_default

错误信息:

FATALERROR:Couldnotfind./bin/my_print_default

If you are using a binary release, you must run this script from

within the directory the archive extracted into. If you compiled

MySQL yourself you must run \'make install\' first.

[root@bogon scripts]# /usr/local/mysql/scripts/mysql_install_db --user=mysql&am

[1] 16874

[root@bogon scripts]#

FATAL ERROR: Could not find ./bin/my_print_default

If you compiled from source, you need to run \'make install\' to copy the software into the correct location ready for operation.

If you are using a binary release, you must either be at the top level of the extracted archive, or pass the --basedir option pointing to that location.

解决方法:

[root@bogon scripts]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data &am

(这点非常重要)

FreeBSD下的解决办法是:

/usr/local/bin/mysql_install_db --user=mysql --basedir=/usr/local/ --datadir=/var/db/mysql &am

*配置慢查询日志

long_query_time = 1 #定义超过1秒的查询计数到变量Slow_queries。

log-slow-queries = /usr/local/mysql/data/slow.log #定义慢查询日志路径。

log-queries-not-using-indexes #未使用索引的查询也被记录到慢查询日志中(可选)。

mysql自带了一个查看慢日志的工具mysqldumpslow。

执行mysqldumpslow –h可以查看帮助信息。

主要介绍两个参数-s和-t

-s 这个是排序参数,可选的有:

al: 平均锁定时间

ar: 平均返回记录数

at: 平均查询时间

c: 计数

l: 锁定时间

r: 返回记录

t: 查询时间

-t n 显示头n条记录。

实例:

mysqldumpslow -s c -t 20 host-slow.log

mysqldumpslow -s r -t 20 host-slow.log

上述命令可以看出访问次数最多的20个sql语句和返回记录集最多的20个sql。

mysqldumpslow -t 10 -s t -g “left join” host-slow.log

这个是按照时间返回前10条里面含有左连接的sql语句。

用了这个工具就可以查询出来那些sql语句是性能的瓶颈,进行优化,比如加索引,该应用的实现方式等。

上一篇:Linux:CentOS7防火墙开放端口配置-时空链接
下一篇:CentOS7如何设置防火墙