首先在MySQL官网下载MySQL二进制包(下载要注册,稍显麻烦) 我下载的mysql-5.1.49,有123M大哦,比源码包大多啦。 # ls -lh mysql-5.1.49-linux-i686-glibc23.tar.gz -rw-r--r-- 1 root root 123M Aug 3 14:20 mysql-5.1.49-linux-i686-glibc23.tar.gz然后放到/usr/local目录下#cd /usr/local/# lsbin etc games include lib libexec mrtg mysql-5.1.49-linux-i686-glibc23.tar.gz rrdtool sbin share src添加MySQL用户,组 # groupadd mysql# useradd -g mysql mysql解压MySQL# tar -zxvf mysql-5.1.49-linux-i686-glibc23.tar.gz建一个符号链接 /usr/local/mysql# ln -s mysql-5.1.49-linux-i686-glibc23 mysql# lltotal 126128drwxr-xr-x 2 root root 4096 Aug 3 14:17 bindrwxr-xr-x 2 root root 4096 Aug 8 2008 etcdrwxr-xr-x 2 root root 4096 Aug 8 2008 gamesdrwxr-xr-x 2 root root 4096 Aug 8 2008 includedrwxr-xr-x 2 root root 4096 Aug 8 2008 libdrwxr-xr-x 2 root root 4096 Aug 8 2008 libexecdrwxr-xr-x 2 root root 4096 May 17 13:57 mrtglrwxrwxrwx 1 root root 31 Aug 3 14:29 mysql -> mysql-5.1.49-linux-i686-glibc23drwxr-xr-x 13 7155 wheel 4096 Jul 11 07:53 mysql-5.1.49-linux-i686-glibc23-rw-r--r-- 1 root root 128915887 Aug 3 14:20 mysql-5.1.49-linux-i686-glibc23.tar.gzdrwxr-xr-x 6 root root 4096 Aug 3 14:17 rrdtooldrwxr-xr-x 2 root root 4096 Aug 8 2008 sbindrwxr-xr-x 4 root root 4096 Apr 15 18:41 sharedrwxr-xr-x 2 root root 4096 Aug 8 2008 src看下MySQL具体的目录结构 # ls mysqlbin data EXCEPTIONS-CLIENT INSTALL-BINARY man README share support-filesCOPYING docs include lib mysql-test scripts sql-benchINSTALL-BINARY 是官方的安装说明 66 The basic commands that you must execute to install and use a67 MySQL binary distribution are:6869 Note7071 The following process assumes that you have root (administrator)72 access to your system. Alternatively you can prefix each command73 using the sudo (Linux) or pfexec (OpenSolaris) command.74 shell> groupadd mysql75 shell> useradd -g mysql mysql76 shell> cd /usr/local77 shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -78 shell> ln -s full-path-to-mysql-VERSION-OS mysql79 shell> cd mysql80 shell> chown -R mysql .81 shell> chgrp -R mysql .82 shell> scripts/mysql_install_db --user=mysql83 shell> chown -R root .84 shell> chown -R mysql data85 shell> bin/mysqld_safe --user=mysql & #cd mysql # pwd/usr/local/mysql修改权限 #chown -R mysql . #chgrp -R mysql .建立MySQL配置文件 support-files下可以看到提供了5个模板,可以根据自己的环境选择。# ls support-files/binary-configure magic my-medium.cnf mysql.serverconfig.huge.ini my-huge.cnf my-small.cnf ndb-config-2-node.iniconfig.medium.ini my-innodb-heavy-4G.cnf mysqld_multi.serverconfig.small.ini my-large.cnf mysql-log-rotate我这里用my-medium.cnf# cp support-files/my-medium.cnf /etc/my.cnf修改配置文件 # vi /etc/my.cnf 文件中添加下面一句,设置自己想要的数据目录。默认在./mysql/data下。我的数据目录设置为/data/mysql datadir = /data/mysql-- {该语句需要加到 [mysqld]数据区域段} 保存退出建立数据目录 # mkdir -p /data/mysql# chown -R mysql /data/mysql# chgrp -R mysql /data/mysql# ll /datatotal 8drwxr-xr-x 2 mysql mysql 4096 Aug 3 14:41 mysql初始化 # ./scripts/mysql_install_db --user=mysql修改权限 #chown -R root .修改数据目录权限 # ll /data/mysql/total 764drwx------ 2 mysql root 4096 Aug 3 14:45 mysql-rw-rw---- 1 mysql mysql 19079 Aug 3 14:45 mysql-bin.000001-rw-rw---- 1 mysql mysql 722735 Aug 3 14:45 mysql-bin.000002-rw-rw---- 1 mysql mysql 38 Aug 3 14:45 mysql-bin.indexdrwx------ 2 mysql root 4096 Aug 3 14:45 test# chown -R mysql:mysql /data/mysql/启动MySQL# ./bin/mysqld_safe --user=mysql & 设置MySQL密码# ./bin/mysqladmin -u root password 123456看看服务是否已启动 # netstat -tunlp |grep 3306tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 5809/mysqld# ps -ef |grep mysqlroot 5707 3339 0 14:50 pts/3 00:00:00 /bin/sh ./bin/mysqld_safe --user=mysqlmysql 5809 5707 0 14:50 pts/3 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql --log-error=/data/mysql/vbird.err --pid-file=/data/mysql/vbird.pid --socket=/tmp/mysql.sock --port=3306root 5836 3339 0 14:54 pts/3 00:00:00 grep mysql把MySQL加入环境变量# echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile# source /etc/profile //使环境变量生效 # echo $PATH /usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin把MySQL加入开机启动#echo "/usr/local/mysql/bin/mysqld_safe --user=mysql &" >>/etc/rc.local 或者# cp support-files/mysql.server /etc/init.d/mysqld# chkconfig --add mysqld |
重启mysql
# /etc/init.d/mysqld restart
# cp share/mysql/my-huge.cnf /etc/my.cnf
# cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld //开机自动启动 mysql。# chmod 755 /etc/rc.d/init.d/mysqld# chkconfig --add mysqld# /etc/rc.d/init.d/mysqld start //启动 MySQL# bin/mysqladmin -u root password "password_for_root"# service mysqld stop //关闭 MySQL