`
ssxxjjii
  • 浏览: 933443 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

centos的5.2,mysql免安装版本

阅读更多

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下。先进入该目录解压。

 

Java代码
  1.  [root @localhost  soft]# cd /home/xjj/soft      
  2.    [root@localhost  soft]# tar -zvxf mysql- 5.1 . 30 -linux-i686-glibc23  
  3. [root@localhost  soft]# cd mysql- 5.1 . 30 -linux-i686-glibc23  
  4.    [root@localhost  mysql- 5.1 . 30 -linux-i686-glibc23]# ls  
  5.      bin      docs   INSTALL-BINARY  mysql-test  share  
  6. COPYING  EXCEPTIONS-CLIENT  lib             README      sql-bench  
  7. data     include            man             scripts     support-files  
 [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下

 

Java代码
  1. [root @localhost  mysql- 5.1 . 30 -linux-i686-glibc23]# mv mysql- 5.1 . 30 -linux-i686-glibc23/ /usr/local/mysql  
  2.  [root@localhost  mysql- 5.1 . 30 -linux-i686-glibc23]# cd /usr/local/mysql  
[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用户。

 

Java代码
  1. [root @localhost  mysql- 5.1 . 30 -linux-i686-glibc23]# groupadd mysql  
  2. [root@localhost  mysql- 5.1 . 30 -linux-i686-glibc23]# useradd -g 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配置文件,先看一下:

 

Java代码
  1. [root @localhost  mysql]# cd support-files/  
  2. [root@localhost  support-files]# ls  
  3.       binary-configure   my-huge.cnf             mysqld_multi.server  
  4.       config.huge.ini    my-innodb-heavy-4G.cnf  mysql-log-rotate  
  5.       config.medium.ini  my-large.cnf            mysql.server  
  6.       config.small.ini   my-medium.cnf           ndb-config-2 -node.ini  
  7.       magic              my-small.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

 

   改文件分别适应于不同的安装配置,具体说明如下。

Java代码
  1. my-small.cnf 最小配置安装,内存<=64M,数据数量最少  
  2. my-large.cnf               内存=512M  
  3. my-medium.cnf             32M<内存<64M,或者内存有128M,但是数据库与web服务器公用内存   
  4. my-huge.cnf               1G<内存<2G,服务器主要运行mysql  
  5. my-innodb-heavy-4G.cnf    最大配置安装,内存至少4G  
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进行配置。

Java代码
  1. [root @localhost  mysql]# cp support-files/my-medium.cnf /etc/my.cnf  
 [root@localhost mysql]# cp support-files/my-medium.cnf /etc/my.cnf

 

  下面进行访问权限配置,用mysql_install_db创建MySQL授权表初始化,并设置mysql,root帐号访问权限

 

Java代码
  1. [root @localhost  mysql]# chown -R mysql .  
  2.     [root@localhost  mysql]# chgrp -R mysql .  
  3.     [root@localhost  mysql]# scripts/mysql_install_db –user=mysql  
  4.     Installing MySQL system tables…  
  5.     OK  
  6.     Filling help tables…  
  7.     OK  
  8. To start mysqld at boot time you have to copy  
  9. support-files/mysql.server to the right place for  your system  
  10. PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !  
  11. To do  so, start the server, then issue the following commands:  
  12. ./bin/mysqladmin -u root password ‘new -password’  
  13. ./bin/mysqladmin -u root -h localhost.localdomain password ‘new -password’  
  14. Alternatively you can run:  
  15. ./bin/mysql_secure_installation  
  16. which will also give you the option of removing the test  
  17. databases and anonymous user created by default .  This is  
  18. strongly recommended for  production servers.  
  19. See the manual for  more instructions.  
  20. You can start the MySQL daemon with:  
  21. cd . ; ./bin/mysqld_safe &  
  22. You can test the MySQL daemon with mysql-test-run.pl  
  23. cd ./mysql-test ; perl mysql-test-run.pl  
  24. Please report any problems with the ./bin/mysqlbug script!  
  25. The latest information about MySQL is available at http://www.mysql.com/   
  26. Support MySQL by buying support/licenses from http://shop.mysql.com/   
  27. [root@localhost  mysql]# chown -R root  
  28. chown: “root” 后缺少操作数  
  29. 请尝试执行“chown –help”来获取更多信息。  
  30. [root@localhost  mysql]# chown -R root .  
  31. [root@localhost  mysql]# chown -R mysql data  
[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。

 

Java代码
  1. [root @localhost  mysql]# bin/mysqld_safe –user=mysql &  
  2. 090105   16 : 57 : 45  mysqld_safe Logging to ‘/var/log/mysqld.log’.  
  3. 090105   1657 : 46  mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql  
  4. 090105   16 : 57 : 49  mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended  
[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中的日志,看看具体的原因。

Java代码
  1. [root @localhost  mysql]# less /var/log/mysqld.log  
  2. …………..  
  3. InnoDB: Apply batch completed  
  4. 090105   17 : 03 : 31   InnoDB: Started; log sequence number  0   46409   
  5. 090105   17 : 03 : 31  [ERROR] /usr/local/mysql/bin/mysqld: Can’t create/write to file   
  6. ‘/var/run/mysqld/mysqld.pid’ (Errcode: 2 )  
  7. 090105   17 : 03 : 31  [ERROR] Can’t start server: can’t create PID file: No such file   
  8. or directory  
  9. 090105   17 : 03 : 31  mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended  
[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不存在,看来要手动创建它了,不要忘记了进行授权。

Java代码
  1. [root @localhost  log]# mkdir /var/run/mysqld  
  2. [root@localhost  log]# cd /var/run/mysqld  
  3. [root@localhost  mysqld]# touch mysqld.pid  
  4. [root@localhost  mysqld]# chown -R mysql mysqld.pid  
  5. [root@localhost  mysqld]# cd /usr/local/mysql  
[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用户设置初始密码。

Java代码
  1. [root @localhost  mysql]# bin/mysqld_safe –user=mysql &  
  2. [root@localhost  mysql]# bin/mysqld_safe –user=mysql &  
  3. [1 5789   
  4. [root@localhost  mysql]#  090105   17 : 32 : 31  mysqld_safe Logging to ‘/var/log/mysqld.log’.  
  5. 090105   17 : 32 : 31  mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql  
  6. [root@localhost  mysql]# bin/mysqladmin -u root password  123   
  7. bin/mysqladmin: connect to server at ‘localhost’ failed  
  8. error: ‘Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2 )’  
  9. Check that mysqld is running and that the socket: ‘/tmp/mysql.sock’ exists!  
[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不存在。

Java代码
  1. [root @localhost  mysql]# cd /tmp  
  2. [root@localhost  tmp]# ls  
  3. gconfd-root     scim-bridge-0.3 . 0 .lockfile- 0 @localhost : 0.0   ssh-yocCKF5691  
  4. keyring-ej0c48  scim-bridge-0.3 . 0 .socket- 0 @localhost : 0.0     virtual-root.8cYaYH  
  5. keyring-RtFEN5  scim-helper-manager-socket-root             virtual-root.v3vfmO  
  6. mapping-root    scim-panel-socket:0 -root  
  7. orbit-root      scim-socket-frontend-root  
[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中,
我们创建一个符号连接即可。

 

Java代码
  1. [root @localhost  mysql]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock  
[root@localhost mysql]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

 

  再次设置root密码,并登录。

Java代码
  1. [root @localhost  mysql]# bin/mysqladmin -u root password  123   
  2. [root@localhost  mysql]# bin/mysql -u root -p  
  3. Enter password:   
  4. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  5. Your MySQL connection id is 3   
  6. Server version: 5.1 . 30  MySQL Community Server (GPL)  
  7. Type ‘help;’ or ‘\h’ for  help. Type ‘\c’ to clear the buffer.  
[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能够开机自启动。

Java代码
  1. [root @localhost  mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld  
  2. [root@localhost  mysql]# chmod  700  /etc/init.d/mysqld  
  3. [root@localhost  mysql]# chkconfig –add mysqld  
  4. [root@localhost  mysql]# chkconfig –level  345  mysqld on  
[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}

 

大家应该很容易理解它们的意思。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics