exceljava 发表于 2013-2-7 12:12:17

centos5.2免编译安装mysql5

         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下。先进入该目录解压。
         
# cd /home/xjj/soft       # tar -zvxf mysql-5.1.30-linux-i686-glibc23# cd mysql-5.1.30-linux-i686-glibc23   # ls   bin      docs   INSTALL-BINARYmysql-testshareCOPYINGEXCEPTIONS-CLIENTlib             README      sql-benchdata   include            man             scripts   support-files 
     可以看到,加压后的目录中并没有configure目录。所以如果你运行./configure的话,会出现找不到文件的错误,我就浪费了时间在这上面。先将加压后的目录mv到/usr/local下
     
# mv mysql-5.1.30-linux-i686-glibc23/ /usr/local/mysql # cd /usr/local/mysql 
     很重要的一步,是创建一个用户组,并在改组下创建一个用户。这里我们创建一个mysql组,并创建一个mysql用户。
   
# groupadd mysql# useradd -g mysql mysql   
     下面添加mysql的配置文件,改文件的模板在mysql/support-files下,共有5个cnf配置文件,先看一下:
  
# cd support-files/# ls      binary-configure   my-huge.cnf             mysqld_multi.server      config.huge.ini    my-innodb-heavy-4G.cnfmysql-log-rotate      config.medium.inimy-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               内存=512Mmy-medium.cnf             32M<内存<64M,或者内存有128M,但是数据库与web服务器公用内存 my-huge.cnf               1G<内存<2G,服务器主要运行mysqlmy-innodb-heavy-4G.cnf    最大配置安装,内存至少4G 
  根据情况,我选择my-medium.cnf进行配置。
 
# cp support-files/my-medium.cnf /etc/my.cnf 
  下面进行访问权限配置,用mysql_install_db创建MySQL授权表初始化,并设置mysql,root帐号访问权限
  
  
# chown -R mysql .    # chgrp -R mysql .    # scripts/mysql_install_db –user=mysql    Installing MySQL system tables…    OK    Filling help tables…    OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE 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_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default.This isstrongly 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.plcd ./mysql-test ; perl mysql-test-run.plPlease 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/# chown -R rootchown: “root” 后缺少操作数请尝试执行“chown –help”来获取更多信息。# chown -R root .# chown -R mysql data 
  
     特别注意,# chown -R root .这里的.号是不能少的。好了,开始启动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/mysql090105 16:57:49 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended 
   启动失败,查看/var/log/mysqld.log中的日志,看看具体的原因。
  
# less /var/log/mysqld.log…………..InnoDB: Apply batch completed090105 17:03:31InnoDB: Started; log sequence number 0 46409090105 17:03:31 /usr/local/mysql/bin/mysqld: Can’t create/write to file ‘/var/run/mysqld/mysqld.pid’ (Errcode: 2)090105 17:03:31 Can’t start server: can’t create PID file: No such file or directory090105 17:03:31 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended 
   原来是/var/run/mysqld/mysqld.pid不存在,看来要手动创建它了,不要忘记了进行授权。
# mkdir /var/run/mysqld# cd /var/run/mysqld# touch mysqld.pid# chown -R mysql mysqld.pid# cd /usr/local/mysql 
  再次启动mysql,并给root用户设置初始密码。
 
# bin/mysqld_safe –user=mysql &# bin/mysqld_safe –user=mysql & 5789# 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# bin/mysqladmin -u root password 123bin/mysqladmin: connect to server at ‘localhost’ failederror: ‘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不存在。
 
# cd /tmp# lsgconfd-root   scim-bridge-0.3.0.lockfile-0@localhost:0.0ssh-yocCKF5691keyring-ej0c48scim-bridge-0.3.0.socket-0@localhost:0.0    virtual-root.8cYaYHkeyring-RtFEN5scim-helper-manager-socket-root             virtual-root.v3vfmOmapping-root    scim-panel-socket:0-rootorbit-root      scim-socket-frontend-root 
  确实不存在mysql.sock文件。一般情况下,mysql 默认的mysql.sock 是在/var/lib/mysql/mysql.sock中,
我们创建一个符号连接即可。
 
# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock 
  再次设置root密码,并登录。
 
# bin/mysqladmin -u root password 123# bin/mysql -u root -pEnter password: Welcome to the MySQL monitor.Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.1.30 MySQL Community Server (GPL)Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer. 
 终于看到久违的熟悉界面了。下面,我们还要配置一下,以便mysql能够开机自启动。
 
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld# chmod 700 /etc/init.d/mysqld# chkconfig –add mysqld# chkconfig –level 345 mysqld on 
 
好了,可以了,然后可以运行service mysqld start 启动mysql。相应的命令还有。
 
{start|stop|restart|reload|force-reload|status}
 
大家应该很容易理解它们的意思。
页: [1]
查看完整版本: centos5.2免编译安装mysql5