mysql的安装详解
时间:2008-03-28 来源:yl2003215059
一、下载源码包:
在各大网站都可以下载。
二、安装mysql
2.1建立mysql用户和组
Shell>groupadd mysql
shell> useradd -g mysql mysq
2.2指定安装的路径
cd mysql-5.0.40/
liangyin@debian:~/mysql-5.0.40$
然后用./configure –-prefix=/usr/local/mysql
2.3编译在安装
最后make;make install
其实make;之后可以用: echo $? 返回上一步的情况,如果出现0.则说明上一步是正确的,否则说明上一步有错。
Echo $?可以用来验证每一个上一步的命令是否正确。
2.4移动mysql的配置文件
cp ./support-files/my-medium.cnf /etc/my.cnf
ls -al /etc/my.cnf
-rw-r--r-- 1 root root 4912 2008-03-27 17:29 /etc/my.cnf
2.5修改权限
debian:/usr/local/mysql# chown -R mysql ./
debian:/usr/local/mysql# chgrp -R mysql ./
debian:/usr/local/mysql# ls -al
total 2
drwxr-sr-x 11 mysql mysql 280 2008-03-27 23:51 .
drwxrwsr-x 16 root staff 424 2008-03-27 23:30 ..
drwxr-sr-x 2 mysql mysql 1552 2008-03-27 23:51 bin
drwxr-sr-x 3 mysql mysql 72 2008-03-27 00:43 include
drwxr-xr-x 2 mysql mysql 80 2008-03-27 23:51 info
drwxr-sr-x 3 mysql mysql 72 2008-03-27 00:43 lib
drwxr-sr-x 2 mysql mysql 104 2008-03-27 23:51 libexec
drwxr-sr-x 3 mysql mysql 72 2008-03-27 23:51 man
drwxr-sr-x 7 mysql mysql 456 2008-03-27 23:51 mysql-test
drwxr-sr-x 3 mysql mysql 72 2008-03-27 23:51 share
drwxr-sr-x 5 mysql mysql 888 2008-03-27 23:51 sql-bench
这样保证:/usr/local/mysql下的文件都属于用户root,所属的组为mysql。
但是有个要例外:就是文件/var。他是属于用户mysql的,所属的组也是。
2.5启动mysql数据库
/home/liangyin/mysql-5.0.40#/usr/local/mysql/bin/mysql_install_db --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h debian password 'new-password'
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 mysql-test ; perl mysql-test-run.pl
2.6启动mysql服务
再次更改权限:/usr/local/mysql/目录下:
shell> chown -R root .
shell> chown -R mysql var
这样做目的:
Most of the MySQL installation can be owned by `root' if you like.
The exception is that the data directory must be owned by `mysql'.
To accomplish this, run the following commands as `root' in the
installation directory:
/usr/local/mysql/bin/mysqld_safe --user=mysql &
#在mysql的bin目录下以用户mysql启动他。
然后可以看到3306.
综上所述就是:
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -
shell> cd mysql-VERSION
shell> ./configure --prefix=/usr/local/mysql
shell> make
shell> make install
shell> cp support-files/my-medium.cnf /etc/my.cnf
#my.cnf这个是mysql的配置文件
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
#先改/usr/local/mysql下面的文件的权限,让用户和组属于mysql。
shell> bin/mysql_install_db --user=mysql
#以用户mysql的身份开启
shell> chown -R root .
shell> chown -R mysql var
shell> bin/mysqld_safe --user=mysql &