现在的位置: 首页 > 数据库 > MySQL > 正文
编译安装LAMP之:安装通用二进制mysql5.5
2013年08月26日 MySQL, Web技术 ⁄ 共 2740字 编译安装LAMP之:安装通用二进制mysql5.5已关闭评论 ⁄ 被围观 7,764 views+

对于一般应用而言,直接安装官方已经编译好的mysql即可,就不需自己编译安装了,具体过程如下:

1、软件准备:

wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.33-linux2.6-x86_64.tar.gz
tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ln -sv mysql-5.5.33-linux2.6-x86_64 mysql ##尽量保留原目录

2、安装初始化:

2.1 创建mysql用户和组:

[root@web1 local]# groupadd -r -g 27 mysql
[root@web1 local]# useradd -r -g 27 -u 27 mysql
[root@web1 local]# grep "mysql" /etc/passwd
mysql:x:27:27::/home/mysql:/bin/bash

2.2 修改mysql属主属组:

chown -R mysql.mysql /usr/local/mysql/*

2.3 准备数据存放目录:

创建数据存放目录

[root@web1 mysql]# mkdir /data

修改数据文件目录权限:

[root@web1 mysql]# chown mysql.mysql /data
[root@web1 mysql]# chmod 750 /data
##建议单独规划一个分区(需lvs)来存放mysql数据文件,方便管理

2.4 运行初始化安装脚本:

[root@web1 mysql]# ls
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files
[root@web1 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data
##脚本运行情况跟使用rpm安装后第一次启动时一样,进行数据库的初始化操作

修改/usr/local/mysql/下文件的权限:

[root@web1 mysql]# chown -R root /usr/local/mysql/*
##此处是为了增强mysql的安全性

2.5 复制启动脚本:

[root@web1 mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@web1 mysql]# ll /etc/init.d/mysqld
-rwxr-xr-x. 1 root root 10880 8月 24 00:15 /etc/init.d/mysqld
[root@web1 mysql]# chkconfig --add mysqld

3、mysql配置文件:

mysql的配置文件格式为集中式,可以为多个程序提供配置,如mysql和mysqld,分段式定义,如:

[client]
……
[mysqld]
……

mysql默认查找配置文件次序为:/etc/my.cnf -->/etc/mysql/my.cnf -->$BASEDIR/my.cnf --> $DATADIR/my.cnf -- ~/.my.cnf
注意:后一个配置文件优先级高于前一个

3.1 复制模板配置文件:

[root@web1 mysql]# cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf

##mysql提供了多个配置文件模板,可根据需要复制

3.2 编辑配置文件:

[root@web1 mysql]# vi /etc/my.cnf
##修改mysql线程数为CPU个数的两倍,如我虚拟机CPU为2,则修改该数值为4
thread_concurrency = 4
##添加data目录定义
datadir=/data

4、管理mysql:

启动mysqld

[root@web1 mysql]# service mysqld start
Starting MySQL............... [确定]

查看运行情况:

[root@web1 mysql]# netstat -tnlp |grep mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 7555/mysqld

测试mysql执行:

[root@web1 ~]# mysql
-bash: mysql: command not found

找不到mysql命令,因此需要添加mysql执行文件路径到PATH路径:

[root@web1 mysql]# vi /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin

保存后退出登录,重新登录后再次执行mysql命令:

[root@web1 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.33-log MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

5、定义其他配置:

定义mysql 帮助文件man:

vi /etc/man.config #添加如下一行就可以使用man mysql咯:
MANPATH /usr/local/mysql/man

为方便启动程序调用mysql库文件,需要输出mysql库文件:

vi /etc/ld.so.conf.d/mysql.conf ##添加如下一行
/usr/local/mysql/lib

保存后执行:ldconfig -v 使其立即生效
库文件会被缓存至:/etc/ld.so.cache,就可以被其他程序调用了

输出头文件:

[root@web1 data]# ln -sv /usr/local/mysql/include /usr/include/mysql
"/usr/include/mysql" -> "/usr/local/mysql/include"

至此,mysql服务安装配置基本完成了。

抱歉!评论已关闭.

×