LAMP平台下构建Postfix邮件服务器(5)

[root@mail mnt]# tar zxvf cmake-2.8.6.tar.gz -C /usr/src

[root@mail mnt]# cd /usr/src/cmake-2.8.6/

[root@mail mnt]# ./configure && make && make install

2、编译安装配置MySQL
  创建所需目录mkdir -pv /usr/local/mysql/data     //同时创建mysql和data两个目录并输出创建信息
  创建mysql组    groupadd mysql
  创建mysql用户 useradd -M -g ysql -s /sbin/nologin mysql  //创建mysql用户并加入mysql组,并不能登录到系统

解压源码
[root@mail mnt]# tar -zxvf mysql-5.5.22.tar.gz -C /usr/src/        /本人一般解压在此目录下面
[root@mail mnt]# cd /usr/src/mysql-5.5.22

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8-

DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -

DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_DEBUG=0

参数说明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
-DMYSQL_DATADIR=/usr/local/mysql/data //数据库存放目录
-DWITH_MYISAM_STORAGE_ENGINE=1 //安装myisam存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 //安装innodb存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 //安装archive存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 //安装blackhole存储引擎
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
-DDEFAULT_CHARSET=utf8   //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci //校验字符
-DEXTRA_CHARSETS=all   //安装所有扩展字符集
-DMYSQL_TCP_PORT=3306 //MySQL监听端口
-DMYSQL_USER=mysql //MySQL用户名

其他参数:
-DWITH-EMBEDDED_SERVER=1 //编译成embedded MySQL library (libmysqld.a)
-DSYSCONFDIR=/etc //MySQL配辑文件
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock //Unix socket 文件路径
-DWITH_READLINE=1 //快捷键功能
-DWITH_SSL=yes //SSL
-DWITH_MEMORY_STORAGE_ENGINE=1 //安装memory存储引擎
-DWITH_FEDERATED_STORAGE_ENGINE=1 //安装frderated存储引擎
-DWITH_PARTITION_STORAGE_ENGINE=1 //安装数据库分区
-DINSTALL_PLUGINDIR=/usr/local/mysql/plugin //插件文件及配置路径

[root@mail mysql-5.5.22]# make && make install

#复制配置文件
[root@mail mysql-5.5.22]# cp support-files/my-medium.cnf /etc/my.cnf
#设置权限
[root@mail mysql-5.5.22]# chmod +x /usr/local/mysql/
[root@mail mysql-5.5.22]# chown -R mysql.mysql /usr/local/mysql/
[root@mail mysql-5.5.22]# chown -R mysql.mysql /usr/local/mysql/data/
[root@mail mysql-5.5.22]#

#配置开机自动启动
[root@mail mysql-5.5.22]# cp support-files/mysql.server /etc/init.d/mysqld
[root@mail mysql-5.5.22]# chmod +x /etc/rc.d/init.d/mysqld
[root@mail mysql-5.5.22]# chkconfig mysqld on
[root@mail mysql-5.5.22]# chkconfig --add mysqld
[root@mail mysql-5.5.22]#
#修改配置文件
vim /etc/my.cnf
#在[mysqld]中添加:
datadir = /usr/local/mysql/data
log-error = /usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mail.pid     //(此处的pid文件名称要与主机名称一致)
user = mysql
tmpdir = /tmp
#保存退出

初始化数据库
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

手动启动MySQL
service mysqld start   //第一次我在这里启动失败,查看日志,提示字符集无效,修改my.cnf配置文件,添加下面设置,后来就没的错误了

[client]
default-character-set=utf8

[mysqld]
character-set-server=utf8

保存退出后重新初始化数据库
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

测试MySQL是否启动
[root@mail mysql-5.5.22]# service mysqld restart
MySQL server PID file could not be found!                  [失败]
Starting MySQL.....                                        [确定]
[root@mail mysql-5.5.22]# netstat -nuptl | grep 3306
tcp        0      0 :::3306                     :::*                        LISTEN      3430/mysqld        
[root@mail mysql-5.5.22]# export PATH=$PATH:/usr/local/mysql/bin
[root@mail mysql-5.5.22]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@mail mysql-5.5.22]# echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
[root@mail mysql-5.5.22]# mysqladmin version  
mysqladmin  Ver 8.42 Distrib 5.5.22, for Linux on i686
Copyright (c) 2000, 2011, 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.

Server version          5.5.22-log
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/lib/mysql/mysql.sock
Uptime:                 2 min 11 sec

Threads: 1  Questions: 1  Slow queries: 0  Opens: 33  Flush tables: 1  Open tables: 26  Queries per second avg: 0.007
[root@mail mysql-5.5.22]#

到此MySQL编译安装完成

第一次登录默认为空密码

mysql -u root  //以管理员身份登录mysql数据库

修改root登录数据库的密码

mysqladmin -u root password "自定义的密码"

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/8ec08036ba540e1de47bf6d2c66f2035.html