首先在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/ # ls bin 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 # ll total 126128 drwxr-xr-x 2 root root 4096 Aug 3 14:17 bin drwxr-xr-x 2 root root 4096 Aug 8 2008 etc drwxr-xr-x 2 root root 4096 Aug 8 2008 games drwxr-xr-x 2 root root 4096 Aug 8 2008 include drwxr-xr-x 2 root root 4096 Aug 8 2008 lib drwxr-xr-x 2 root root 4096 Aug 8 2008 libexec drwxr-xr-x 2 root root 4096 May 17 13:57 mrtg lrwxrwxrwx 1 root root 31 Aug 3 14:29 mysql -> mysql-5.1.49-linux-i686-glibc23 drwxr-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.gz drwxr-xr-x 6 root root 4096 Aug 3 14:17 rrdtool drwxr-xr-x 2 root root 4096 Aug 8 2008 sbin drwxr-xr-x 4 root root 4096 Apr 15 18:41 share drwxr-xr-x 2 root root 4096 Aug 8 2008 src
看下MySQL具体的目录结构 # ls mysql bin data EXCEPTIONS-CLIENT INSTALL-BINARY man README share support-files COPYING docs include lib mysql-test scripts sql-bench
INSTALL-BINARY 是官方的安装说明
66 The basic commands that you must execute to install and use a 67 MySQL binary distribution are: 68 69 Note 70 71 The following process assumes that you have root (administrator) 72 access to your system. Alternatively you can prefix each command 73 using the sudo (Linux) or pfexec (OpenSolaris) command. 74 shell> groupadd mysql 75 shell> useradd -g mysql mysql 76 shell> cd /usr/local 77 shell> gunzip 78 shell> ln -s full-path-to-mysql-VERSION-OS mysql 79 shell> cd mysql 80 shell> chown -R mysql . 81 shell> chgrp -R mysql . 82 shell> scripts/mysql_install_db --user=mysql 83 shell> chown -R root . 84 shell> chown -R mysql data 85 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.server config.huge.ini my-huge.cnf my-small.cnf ndb-config-2-node.ini config.medium.ini my-innodb-heavy-4G.cnf mysqld_multi.server config.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 /data total 8 drwxr-xr-x 2 mysql mysql 4096 Aug 3 14:41 mysql
初始化 # ./scripts/mysql_install_db --user=mysql
修改权限 #chown -R root .
修改数据目录权限 # ll /data/mysql/ total 764 drwx------ 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.index drwx------ 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 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 5809/mysqld # ps -ef |grep mysql root 5707 3339 0 14:50 pts/3 00:00:00 /bin/sh ./bin/mysqld_safe --user=mysql mysql 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=3306 root 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
|