centos的版本是5.2,mysql的版本是最新的稳定版本5.1.30. 我的安装包是mysql-5.1.30-linux-i686-glibc23.tar.gz。该版本是免编译版本。安装过程中不需要make。第一次安装免编译版,第一次安装5.1,安装过程中还是碰到了一些问题。不过,历尽千辛,一切ok了。
我把mysql-5.1.30-linux-i686-glibc23.tar.gz放在/home/xjj/soft下。先进入该目录解压。
[root@localhost soft]# cd /home/xjj/soft
[root@localhost soft]# tar -zvxf mysql-5.1.30-linux-i686-glibc23
[root@localhost soft]# cd mysql-5.1.30-linux-i686-glibc23
[root@localhost mysql-5.1.30-linux-i686-glibc23]# ls
bin docs INSTALL-BINARY mysql-test share
COPYING EXCEPTIONS-CLIENT lib README sql-bench
data include man scripts support-files
可以看到,加压后的目录中并没有configure目录。所以如果你运行./configure的话,会出现找不到文件的错误,我就浪费了时间在这上面。先将加压后的目录mv到/usr/local下
[root@localhost mysql-5.1.30-linux-i686-glibc23]# mv mysql-5.1.30-linux-i686-glibc23/ /usr/local/mysql
[root@localhost mysql-5.1.30-linux-i686-glibc23]# cd /usr/local/mysql
很重要的一步,是创建一个用户组,并在改组下创建一个用户。这里我们创建一个mysql组,并创建一个mysql用户。
[root@localhost mysql-5.1.30-linux-i686-glibc23]# groupadd mysql
[root@localhost mysql-5.1.30-linux-i686-glibc23]# useradd -g mysql mysql
下面添加mysql的配置文件,改文件的模板在mysql/support-files下,共有5个cnf配置文件,先看一下:
[root@localhost mysql]# cd support-files/
[root@localhost 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
改文件分别适应于不同的安装配置,具体说明如下。
my-small.cnf 最小配置安装,内存<=64M,数据数量最少
my-large.cnf 内存=512M
my-medium.cnf 32M<内存<64M,或者内存有128M,但是数据库与web服务器公用内存
my-huge.cnf 1G<内存<2G,服务器主要运行mysql
my-innodb-heavy-4G.cnf 最大配置安装,内存至少4G
根据情况,我选择my-medium.cnf进行配置。
[root@localhost mysql]# cp support-files/my-medium.cnf /etc/my.cnf
下面进行访问权限配置,用mysql_install_db创建MySQL授权表初始化,并设置mysql,root帐号访问权限
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
[root@localhost mysql]# scripts/mysql_install_db –user=mysql
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:
./bin/mysqladmin -u root password ‘new-password’
./bin/mysqladmin -u root -h localhost.localdomain password ‘new-password’
Alternatively you can run:
./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 . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl
Please report any problems with the ./bin/mysqlbug script!
The latest information about MySQL is available at http://www.mysql.com/
Support MySQL by buying support/licenses from http://shop.mysql.com/
[root@localhost mysql]# chown -R root
chown: “root” 后缺少操作数
请尝试执行“chown –help”来获取更多信息。
[root@localhost mysql]# chown -R root .
[root@localhost mysql]# chown -R mysql data
特别注意,[root@localhost mysql]# chown -R root .这里的.号是不能少的。好了,开始启动mysql。
[root@localhost mysql]# bin/mysqld_safe –user=mysql &
090105 16:57:45 mysqld_safe Logging to ‘/var/log/mysqld.log’.
090105 1657:46 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
090105 16:57:49 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
启动失败,查看/var/log/mysqld.log中的日志,看看具体的原因。
[root@localhost mysql]# less /var/log/mysqld.log
…………..
InnoDB: Apply batch completed
090105 17:03:31 InnoDB: Started; log sequence number 0 46409
090105 17:03:31 [ERROR] /usr/local/mysql/bin/mysqld: Can’t create/write to file
‘/var/run/mysqld/mysqld.pid’ (Errcode: 2)
090105 17:03:31 [ERROR] Can’t start server: can’t create PID file: No such file
or directory
090105 17:03:31 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
原来是/var/run/mysqld/mysqld.pid不存在,看来要手动创建它了,不要忘记了进行授权。
[root@localhost log]# mkdir /var/run/mysqld
[root@localhost log]# cd /var/run/mysqld
[root@localhost mysqld]# touch mysqld.pid
[root@localhost mysqld]# chown -R mysql mysqld.pid
[root@localhost mysqld]# cd /usr/local/mysql
再次启动mysql,并给root用户设置初始密码。
[root@localhost mysql]# bin/mysqld_safe –user=mysql &
[root@localhost mysql]# bin/mysqld_safe –user=mysql &
[1] 5789
[root@localhost mysql]# 090105 17:32:31 mysqld_safe Logging to ‘/var/log/mysqld.log’.
090105 17:32:31 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[root@localhost mysql]# bin/mysqladmin -u root password 123
bin/mysqladmin: connect to server at ‘localhost’ failed
error: ‘Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)’
Check that mysqld is running and that the socket: ‘/tmp/mysql.sock’ exists!
从错误提示可以看出,可能是/tmp/mysql.sock不存在。
[root@localhost mysql]# cd /tmp
[root@localhost tmp]# ls
gconfd-root scim-bridge-0.3.0.lockfile-0@localhost:0.0 ssh-yocCKF5691
keyring-ej0c48 scim-bridge-0.3.0.socket-0@localhost:0.0 virtual-root.8cYaYH
keyring-RtFEN5 scim-helper-manager-socket-root virtual-root.v3vfmO
mapping-root scim-panel-socket:0-root
orbit-root scim-socket-frontend-root
确实不存在mysql.sock文件。一般情况下,mysql 默认的mysql.sock 是在/var/lib/mysql/mysql.sock中,
我们创建一个符号连接即可。
[root@localhost mysql]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
再次设置root密码,并登录。
[root@localhost mysql]# bin/mysqladmin -u root password 123
[root@localhost mysql]# bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.30 MySQL Community Server (GPL)
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
终于看到久违的熟悉界面了。下面,我们还要配置一下,以便mysql能够开机自启动。
[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chmod 700 /etc/init.d/mysqld
[root@localhost mysql]# chkconfig –add mysqld
[root@localhost mysql]# chkconfig –level 345 mysqld on
好了,可以了,然后可以运行service mysqld start 启动mysql。相应的命令还有。
{start|stop|restart|reload|force-reload|status}
大家应该很容易理解它们的意思。