应用系统是centos 6.x mysql 5.1版本
提前可以把selinux 和iptables 关闭
[[email protected] ~]# chkconfig iptables off
[[email protected] ~]# chkconfig ip6tables off
[[email protected] ~]# /etc/init.d/iptables stop
[[email protected] ~]# /etc/init.d/ip6tables stop
[[email protected] ~]# sed -i "s/LINUX=.*/LINUX=disabled/g" /etc/selinux/config
更改完selinux后要想生效需要重启一下服务器,reboot或者shutdown -r now
yum install make apr* autoconf automake gcc gcc-c++ openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch
这些是支持包 为了防止报错 提前yum 一下
1 下载MySQL数据库l到/usr/local/src/
[[email protected] tmp]# cd /usr/local/src/
[[email protected] src]# wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-i686-glibc23.tar.gz
http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz
有可能会报错:说明你可能没有安装wget工具,执行yum install -y wget安装wget这个工具,这边还要注意一下自己系统的版本有32位和64位的,根据自己的版本下载对应的mysql。下面我安装的是32位,步骤是一样的。
[[email protected] src]# ls
mysql-5.1.73-linux-i686-glibc23.tar.gz
下载完毕,过程可能有点慢,可能跟自己的网速有点关系。
[[email protected] src]# du -sh mysql-5.1.73-linux-i686-glibc23.tar.gz
124M mysql-5.1.73-linux-i686-glibc23.tar.gz
2 解压
[[email protected] src]# tar zxvf mysql-5.1.73-linux-i686-glibc23.tar.gz
[[email protected] src]# ls
mysql-5.1.73-linux-i686-glibc23
mysql-5.1.73-linux-i686-glibc23.tar.gz
[[email protected] src]# du -sh mysql-5.1.73-linux-i686-glibc23
410M mysql-5.1.73-linux-i686-glibc23
3 把解压完的数据移动到/usr/local/mysql
[[email protected] src]# mv mysql-5.1.73-linux-i686-glibc23 /usr/local/mysql
4 建立mysql用户
[[email protected] src]# useradd -s /sbin/nologin -M mysql
创建一个运行MySQL用户 -s 不登录 -M 不创建家目录
5 拷贝配置文件
[[email protected] mysql]# ls
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files
[[email protected] mysql]# cd support-files/
[[email protected] support-files]# ls
binary-configure my-huge.cnf mysqld_multi.server
config.huge.ini my-innodb-heavy-4G.cnf mysql-log-rotate
config.medium.ini my-large.cnf mysql.server
config.small.ini my-medium.cnf ndb-config-2-node.ini
magic my-small.cnf
[[email protected] support-files]# cat /etc/my.cnf
(系统创建的配置文件,不需要,然后直接覆盖就可以了)
[[email protected] support-files]# cp my-large.cnf /etc/my.cnf
6 拷贝启动脚本文件并修改其属性
[[email protected] support-files]# ls
binary-configure my-huge.cnf mysqld_multi.server
config.huge.ini my-innodb-heavy-4G.cnf mysql-log-rotate
config.medium.ini my-large.cnf mysql.server
config.small.ini my-medium.cnf ndb-config-2-node.ini
magic my-small.cnf
[[email protected] support-files]# ls /etc/init.d/
abrt-ccpp cgred kdump nfslock restorecond smartd
abrtd cpuspeed killall ntpd rngd sshd
abrt-oops crond lvm2-lvmetad ntpdate rpcbind sssd
acpid cups lvm2-monitor numad rpcgssd sysstat
atd functions mdmonitor oddjobd rpcidmapd udev-post
auditd haldaemon messagebus portreserve rpcsvcgssd winbind
autofs halt netconsole postfix rsyslog ypbind
blk-availability ip6tables netfs psacct sandbox
certmonger iptables network quota_nld saslauthd
cgconfig irqbalance nfs rdisc single
[[email protected] support-files]# cp mysql.server /etc/init.d/mysqld
[[email protected] support-files]# mkdir -p /data/mysql
(创建一个独立的/data/分区)
[[email protected] support-files]# chown -R mysql /data/mysql/
(把所有者改成mysql)
[[email protected] support-files]# vi /etc/init.d/mysqld
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir=/usr/local/mysql
datadir=/data/mysql/
[[email protected] support-files]#ll /etc/init.d/mysqld (查看权限)
-rwxr-xr-x. 1 root root 12511 4月 8 17:00 /etc/init.d/mysqld
7 初始化数据库
[[email protected] src]# cd /usr/local/mysql/
[[email protected] mysql]# ls
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/
初始化库 --user 定义数据库的所属主, --datadir 定义数据库安装到哪里,建议放到大空间的分区上,这个目录需要自行创建。
[[email protected] mysql]# echo $? (结果为0,说明运行结果正常)
0
9 把启动脚本加入系统服务项,并设定开机启动,启动mysql
[[email protected] support-files]# chkconfig --add mysqld
[[email protected] support-files]# chkconfig mysqld on
[[email protected] support-files]# chkconfig --list |grep mysqld
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[[email protected] mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
10 启动成功我们来检测一下
[[email protected] profile.d]# netstat -lnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:*
查看一下端口 3306 ok
[[email protected] mysql]# /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73-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> quit
登陆一下 ok,因为是源码包安装,登陆的话路径太长,以后用的时候很麻烦,这边我们更改一下
11 扩展知识
[[email protected] ~]# vim /etc/profile.d/path.sh
新建一个path的文件,添加下面内容:
#!/bin/bash
export PATH=$PATH:/usr/local/mysql/bin
保存,退出。ok 直接输入mysql 哈哈 成功
[[email protected] ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73-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>
到这里我的mysql 安装完毕 谢谢