源码安装MySQL5.5.24(基于CentOS或者Redhat5.4操作系统)

一、源码安装MySQL5.5GA准备工作


1.1.创建组和用户:

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


1.2.解压缩安装包:

[root@mysql]# cd /home/mysql/
[root@mysql]# tar xvfz mysql-5.5.24.tar.gz
[root@mysql]# mkdir -R /usr/local/mysql


1.3.配置 yum源
我们用CentOS网上普遍在用的163的源

vi /etc/yum.repos.d/CentOS6-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-5 - Base - 163.com
baseurl=http://mirrors.163.com/centos/5/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-5 - Updates - 163.com
baseurl=http://mirrors.163.com/centos/5/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-5 - Extras - 163.com
baseurl=http://mirrors.163.com/centos/5/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-5 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/5/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-5 - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/5/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

注意:
1).出现如下错误需要将 CentOS6-Base.repo中的$releaserver 替换为5,上面配置已改为5

Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
http://mirrors.163.com/centos/5Server/addons/i386/repodata/repomd.xml: [Errno 14] HTTP Error 404: Not Found
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: addons. Please verify its path and try again”


2).如在使用的操作系统是redhat下使用yum源时出现如下错误,需要使用如下命令导入rpm签名:

Public key for xmlrpc-c-client-1.16.24-1206.1840.4.el5.i386.rpm is not installed
[root@mysql]cd /etc/pki/rpm-gpg
[root@mysql]wget http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
[root@mysql]rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

也就是在/etc/pki/rpm-gpg 下你得有这个CentOS的签名,默认如下



1.4.检查依赖的软件包,如果缺少相关的软件包,可通过yum install或rpm安装:
下面使用 root权限执行

#yum install -y cmake gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libmcrypt* libtool* bison


1.5.进入mysql安装包目录,执行cmake并加载适当参数):

[root@mysql]cd /home/mysql/mysql-5.5.24
[root@mysql]cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DWITH_SERVER_SUFFIX=mysqltest_edition -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_SSL=yes -DWITH_EMBEDDED_SERVER=1 -DWITH_PTHREAD=1 -DMYSQL_USER=mysql -DWITH_MYSQLD_LDFLAGS=-all-static -DWITH_INNOBASE_STORAGE_ENGINE=1 > /home/mysql/mysql_setuplogs_cmake.log 2>&1

说明:MySQL 从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake 工具。

configure 与cmake 参数对照指南:
http://dev.mysql.com/doc/internals/en/installation-layout-options.html
提示:如果编译不成功,重新编译需要删除mysql安装包目录下的CMakeCache.txt文件,即执行:

root>#rm CMakeCache.txt

1.5.1).继续执行编译:

root>#make > /home/mysql/mysql_setuplogs_make.log 2>&1

#真正开始在/usr/local/mysql目录下安装数据库软件

root>#make install > /home/mysql/mysql_setuplogs_makeinstall.log 2>&1


1.6.修改相关路径权限:

root># cd /usr/local/
root># chown -R mysql:mysql mysql

#建议在开始就更改。


1.7.复制程序文件到/usr/bin目录下,方便调用:

[root@mysql local]# cp /usr/local/mysql/bin/mysql* /usr/bin/
至此,MySQL数据库软件安装完全,此时已可使用mysql命令行工具连接其它MySQL数据库服务器了。


二、创建数据库

2.1.创建目录并修改权限:

[root@mysql local]# cd /data
[root@mysql data]# mkdir mysqldata
[root@mysql data]# cd mysqldata
[root@mysql mysqldata]# mkdir 3306
[root@mysql mysqldata]# cd 3306
[root@mysql 3306]# mkdir data binlog tmp innodb_ts innodb_log
[root@mysql 3306]# cd /data
[root@mysql data]# chown - R mysql:mysql mysqldata


2.2.创建数据库:

[root@mysql local]# cd /usr/local/mysql/
[root@mysql mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysqldata/3306/data
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h 127.0.0.1 password 'new-password'

Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/local/mysql/scripts/mysqlbug script!


2.3.编辑和修改my.cnf配置文件,my.cnf如下:

[client]
port = 3306
socket = /data/mysqldata/3306/mysql.sock
default-character-set = utf8
#Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
user = mysql
socket = /data/mysqldata/3306/mysql.sock
pid-file = /data/mysqldata/3306/mysql.pid
basedir = /usr/local/mysql                                    
datadir = /data/mysqldata/3306/data   这2个路径必须和2.1小节实际目录一致,否则会出现Table 'mysql.plugin' doesn't exist

tmpdir = /data/mysqldata/3306/tmp
open_files_limit = 10240
server-id = 303306
lower_case_table_names = 1
character_set_server = utf8
skip-name-resolve
max_connections = 500
max_connect_errors = 100000
max_allowed_packet = 512M
max_heap_table_size = 1024M
max_length_for_sort_data = 4096
back_log=100
interactive_timeout = 600
wait_timeout = 600
default_storage_engine = InnoDB
net_buffer_length = 8K
sort_buffer_size = 2M
join_buffer_size = 4M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
query_cache_size = 128M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
thread_cache_size = 300
table_open_cache = 1024
tmp_table_size = 256M
#*********** Logs related settings ***********
log_bin = /data/mysqldata/3306/binlog/mysql-bin
binlog_format=row
binlog_cache_size=32m
max_binlog_cache_size=512m
max_binlog_size=512m
long_query_time = 1
log_output = FILE
log_error = /data/mysqldata/3306/mysql-error.log
slow_query_log = 1
slow_query_log_file = /data/mysqldata/3306/slow_statement.log
#log_queries_not_using_indexes
general_log = 0
general_log_file = /data/mysqldata/3306/general_statement.log
expire-logs-days = 14
#*********** MyISAM Specific options ***********
key_buffer_size = 32M
bulk_insert_buffer_size = 32M
myisam_sort_buffer_size = 64M
myisam_max_sort_file_size = 2G
myisam_repair_threads = 1
myisam_recover
#*********** INNODB Specific options ***********
innodb_file_per_table
transaction-isolation = READ-COMMITTED
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 512M
innodb_data_home_dir = /data/mysqldata/3306/innodb_ts
innodb_data_file_path = ibdata1:2048M:autoextend:max:8192M
innodb_thread_concurrency = 0
innodb_log_buffer_size = 16M
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
innodb_log_group_home_dir = /data/mysqldata/3306/innodb_log
innodb_flush_log_at_trx_commit = 2
innodb_max_dirty_pages_pct = 80
innodb_lock_wait_timeout = 120
innodb_flush_method=O_DIRECT
[mysqldump]
quick
max_allowed_packet = 512M
[mysql]
no-auto-rehash
prompt=" \\u@\\h \\R:\\m:\\s \\d> "
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 20M
read_buffer_size = 2M
write_buffer_size = 2M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192


2.4.启动数据库:

su - mysql
mysql>$ mysqld_safe --defaults-file=/etc/my.cnf &

注意:如果提示  max_open_files to more than 1024 (request: 4607)错误,请配置mysql用户在/etc/secrity/limits.conf中的如下参数值:

mysql           hard    nofile          8192
mysql           soft    nofile          1200

如果是测试环境,也可以直接用root账号


2.5.设置超级用户密码(mysql用户下):

mysql>$ mysqladmin -uroot password 'root123..' -S /data/mysqldata/3306/mysql.sock

可以通过netstat或ps等命令查看mysqld是否正常加载,由于默认指定mysqld端口号为3306,因此通过netstat查看是否存在3306端口即可,例如:

mysql>$netstat -lnt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:864 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:11111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:16851 0.0.0.0:* LISTEN
0 0 0.0.0.0:21 0.0.0.0:* LISTEN


2.6.使用mysql命令行连接:

[mysql@mysqldb2 mysql]$ mysql -uroot -proot123.. -S /data/mysqldata/3306/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.5.24-log Source distribution
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.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>


三、后续动作

3.1.删除本机匿名连接的空密码帐号:

/usr/local/mysql/bin/mysql -uroot -proot123..
mysql>use mysql; //选择系统数据库mysql
mysql>select Host,User,Password from user; //查看所有用户
mysql>delete from user where password="";
mysql>flush privileges;
mysql>select Host,User,Password from user; //确认密码为空的用户是否已全部删除
mysql>exit;


3.2.进入mysql安装目录下的支持文件目录:

[root@mysqldb2 mysql]# cd /usr/local/mysql/support-files/


3.3.复制服务文件以使MYSQL能用service直接启动:

[root@mysqldb2 mysql]# cp ./mysql.server /etc/init.d/mysqld


3.4.再拷贝已配置好的cnf参数文件到/etc/my.cnf,方便service启动时的读取

[root@mysqldb2 mysql]# cp /data/mysqldata/3306/my.cnf /etc/my.cnf


3.5.尝试用service命令来启动、关闭MYSQL Server

[mysql@mysqldb2 mysql]$ service mysqld restart
Shutting down MySQL....[ OK ]
Starting MySQL.[ OK ]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值