Ubuntu,Mysql二进制安装流程以及常见错误

Ubuntu,Mysql二进制安装流程以及常见错误

分类: 服务器调试及管理 LINUX_STEP_BY_STEP文档 1644人阅读 评论(1) 收藏 举报

前言

      这篇博文是以前写的,有些地方不是很专业,大家凑合看吧,当然按照步骤成功安装MYSQL是不成问题的。


安装环境说明:


系统:ubuntu 11.10
MySql:mysql 5.5.17


1,在Root下尝试
       主要由于我在普通用户下的权限问题搞的有点头大,所以切了过来。
     1.1 MYSQL安装
              在这里先列一下安装说明里面的解答:

  1.   To install and use a MySQL binary distribution, the basic command  
  2.   sequence looks like this:  
  3.   shell> groupadd mysql  
  4.   shell> useradd -r -g mysql mysql  
  5.   shell> cd /usr/local  
  6.   shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz  
  7.   shell> ln -s full-path-to-mysql-VERSION-OS mysql  
  8.   shell> cd mysql  
  9.   shell> chown -R mysql .  
  10.   shell> chgrp -R mysql .  
  11.   shell> scripts/msql_install_db --user=mysql  
  12.   shell> chown -R root .  
  13.   shell> chown -R mysql data  
  14. # Next command is optional  
  15.   shell> cp support-files/my-medium.cnf /etc/my.cnf  
  16.   shell> bin/mysqld_safe --user=mysql &  
  17. # Next command is optional  
  18.   shell> cp support-files/mysql.server /etc/init.d/mysql.server  
      在普通用户下尝试多次后,还是遇到数据库无法启动的问题,所以,我切到root用户下安装,
      提示:ubuntu默认root不设密码,所以你无法登录,在当前用户下,终端输入:sudo passwd root     输入当前用户登录密码,再设置root用户密码就可以了

      附命令记录:      

  1. cd /etc  
  2. rm my.cnf   
  3. rm -rf mysql/  
  4. cd /  
  5. find -name "mysql" -print  
  6. cd /etc/apparmor.d/abstractions/  
  7. rm -rf mysql   
  8.    
以上命令是因为已经安装过mysql,会遗留一些垃圾文件,搜寻一下,全部删除。
  1. groupadd mysql  
  2. useradd -r -g mysql mysql  
  3. cd /usr/local  
  4. cd src  
  5. ln -s /usr/local/src/mysql-5.5.17-linux2.6-i686/ mysql  
  6. cd mysql  
  7. chown -R mysql .  
  8. chgrp -R mysql .  
  9. scripts/mysql_install_db --user=mysql  
  10. chown -R root .  
  11. chgrp -R mysql .  
  12. chown -R root .  
  13. chown -R mysql data  
  14. ls -l  
  15. bin/mysqld_safe --user=mysql &  

      前面可能因为没有chown -R mysql data产生了一系列问题,不知道是不是根本原因所在,先记录一下。执行到这地方,命令行会返回一个进程号,终端提示mysql进程启动,一定没有报错才行。这证明mysql启动了。
   1.2 测试服务
        新开一个终端,进行如下操作:

  1. /usr/local/mysql/bin/mysqladmin version  
正常是返回如下:
       root@air:~# /usr/local/mysql/bin/mysqladmin version
        /usr/local/mysql/bin/mysqladmin  Ver 8.42 Distrib 5.5.17, for linux2.6 on i686
          Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
            Oracle is a registered trademark of Oracle Corporation and/or its
  affiliates. Other names may be trademarks of their respective
  owners.
   Server version 5.5.17
  Protocol version 10
  Connection Localhost via UNIX socket
  UNIX socket /tmp/mysql.sock
  Uptime: 1 min 5 sec
   Threads: 1  Questions: 1  Slow queries: 0  Opens: 33  Flush tables: 1  Open tables: 26  Queries per second avg: 0.015
1.3配置参数  

接下来,我们把默认的配置文件复制到/etc文件夹下,命名为my.cnf文件,命令如下:

  1. cd /usr/local/mysql  
  2. cp support-files/my-medium.cnf /etc/my.cnf  

    现在我们做好了启动服务的准备工作,可以启动了:

  1. bin/mysql -u root -p  
如果正常,返回如下:
  root@air:/usr/local/mysql# bin/mysql -u root 
 
  Welcome to the MySQL monitor.  Commands end with ; or \g.
  Your MySQL connection id is 2
       Server version: 5.5.17 MySQL Community Server (GPL)
       Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective
 owners.
 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  mysql> 
 # 输\s看下状态,\q退出。
1.4安全配置
      现在我们服务起来了,但是密码等都没有设置,接下来我们可以运行如下命令:

  1. root@air:/usr/local/mysql# bin/mysql_secure_installation   
  返回如下:我列举出来,其实可以按着INSTALL-BINARY说明文件中的两条语句手工设置密码,删除TEST数据库,和匿名用户等操作,(从安全性讲,一定要做如上动作)但是推荐还是用上面的语句一并设置。
  1. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL  
  2.         SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!  
  3. In order to log into MySQL to secure it, we'll need the current  
  4. password for the root user.  If you've just installed MySQL, and  
  5. you haven't set the root password yet, the password will be blank,  
  6. so you should just press enter here.  
  7.   
  8. Enter current password for root (enter for none):   
  9. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)  
  10. Enter current password for root (enter for none):   
  11. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)  
  12. Enter current password for root (enter for none):   
  13. OK, successfully used password, moving on...  
  14.   
  15. Setting the root password ensures that nobody can log into the MySQL  
  16. root user without the proper authorisation.  
  17. Set root password? [Y/n] y  
  18. New password:   
  19. Re-enter new password:   
  20. Password updated successfully!  
  21. Reloading privilege tables..  
  22.  ... Success!  
  23.  By default, a MySQL installation has an anonymous user, allowing anyone  
  24.  to log into MySQL without having to have a user account created for  
  25.  them.  This is intended only for testing, and to make the installation  
  26.  go a bit smoother.  You should remove them before moving into a  
  27.  production environment.  
  28.  Remove anonymous users? [Y/n] y  
  29.   ... Success!  
  30. Normally, root should only be allowed to connect from 'localhost'.  This  
  31. ensures that someone cannot guess at the root password from the network.  
  32.    Disallow root login remotely? [Y/n] y  
  33.   ... Success!  
  34. By default, MySQL comes with a database named 'test' that anyone ca  
  35. access.  This is also intended only for testing, and should be removed  
  36. before moving into a production environment.  
  37. Remove test database and access to it? [Y/n] y  
  38. - Dropping test database...  
  39. ERROR 1010 (HY000) at line 1: Error dropping database (can't rmdir './test/', errno: 17)  
  40.  ... Failed!  Not critical, keep moving...  
  41.   - Removing privileges on test database...  
  42.    ... Success!  
  43. Reloading the privilege tables will ensure that all changes made so far  
  44. will take effect immediately.  
  45.    Reload privilege tables now? [Y/n] y  
  46.   ... Success!  
  47.   
  48. Cleaning up...  
  49.    All done!  If you've completed all of the above steps, your MySQL  
  50.    installation should now be secure.  
  51.   
  52.    Thanks for using MySQL!  

2.环境变量以及自启动

    2.1 配置环境变量  
        但是我们发现每次运行命令基本上都要输入绝对路径,或者在安装目录下运行bin/###.##等,如果用apt-get安装的话是不会遇到这个问题的,主要是安装程序已经帮你做了。这里面我们设置环境变量来解决这个问题,类似Windows下配置JDK环境,需要设置JAVA命令PATH一样,在Ubuntu下,环境变量可以设置成用户级或者系统级,区别是对单个用户还是对全局用户都生效,是对BASH生效还是其他等等,这个我也刚接触,列举下面的操作流程和方法,我采用系统级变量:
        系统环境变量一般保存在下面的文件中:
       /etc/environment
       /etc/profile
       /etc/bash.bashrc
        /etc/profile和 /etc/bash.bashrc在Ubuntu 10.0版本中不推荐使用。
       如想将一个路径加入到$PATH中,可以像下面这样做(修改/etc/profile):

  1. $ sudo nano /etc/profile  

添加如下语句:

  1. export PATH="$PATH:/my_new_path"  
你可以自己加上指定的多个路径,中间用冒号隔开。环境变量更改后,在用户下次登陆时生效,如果想立刻生效,则可执行下面的语句:
  1. $source /etc/profile  

       需要注意的是,最好不要把当前路径”./”放到PATH里,这样可能会受到意想不到的攻击。
       其他文件的修改方式与此类似,需要注意的是/etc/environment不需要使用export设置环境变量,其他profile文件需要。
        这样所有用户下的终端都认识/usr/local/mysql/bin下的命令了。
2.2 配置自启动
   可以如下启动:

  1. /usr/local/mysql/bin/mysqld //启动Mysql服务    
  2. /usr/local/mysql/bin/mysql -u root //访问Mysql服务器  
  3. /usr/local/mysql/bin/mysqladmin -u root -p shutdown   //关闭mysql服务器  
   最好应该使其运行在后台:
  1. /usr/local/mysql/bin/mysqld &  
   让服务开机自动运行
  1. cp /usr/local/mysql/support-files/my.server /etc/init.d/mysqld  
  2. sudo update-rc.d mysqld default  
     把mysqld加入到服务中,重新启动机器即可
     当然以后启动可以直接输入 
  1. /etc/init.d/mysqld restart|start  
      到此,MYSQL的安装工作基本已经做完了。

几个常见错误:

常见错误1:
第一次在普通用户权限下安装,可能因为权限的问题,并丢失了一个操作步骤,所以导致安装成功,但是每次启动总报错:
  1. air@air:/usr/local/mysql/bin$ sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &  
  2. [1] 6378  
  3. air@air:/usr/local/mysql/bin$ 111116 11:58:56 mysqld_safe Logging to '/var/log/mysql/error.log'.  
  4. touch: 无法创建"/var/log/mysql/error.log": 没有那个文件或目录  
  5. chown: 无法访问"/var/log/mysql/error.log": 没有那个文件或目录  
  6. 111116 11:58:56 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql  
  7. /usr/local/mysql/bin/mysqld_safe: 107: /usr/local/mysql/bin/mysqld_safe: cannot create /var/log/mysql/error.log: Directory nonexistent  
  8. /usr/local/mysql/bin/mysqld_safe: 1: eval: cannot create /var/log/mysql/error.log: Directory nonexistent  
  9. 111116 11:58:57 mysqld_safe mysqld from pid file /var/lib/mysql/air.pid ended  
从上面看,应该是设置 MYSQL安装文件夹下data用户以及用户组的问题,因为这个是我唯一没有做的操作,可能导致权限一系列问题。 至于所谓.pid文件,并不需要创建,这个和.sock文件是动态自动创建的。怀疑是由于用了mysql用户,但是属性变成了当前用户air,导致这个问题产生。
希望有大牛能够指点一下,不是很明白。


常见错误2:

  1.  air@air:/usr/local/mysql$ scripts/mysql_install_db --user=mysql  
  2.   FATAL ERROR: Could not find mysqld  
  3.            The following directories were searched:  
  4.            /usr/libexec  
  5.             /usr/sbin  
  6.             /usr/bin  
  7. If you compiled from source, you need to run 'make install' to copy the software into the correct location ready for operation.  
  8. If you are using a binary release, you must either be at the top level of the extracted archive, or pass the --basedir option pointing to that locatio  
解决方案:这个问题说的比较明显,对于二进制安装来说,一定要在/usr/local文件夹下安装,解压的时候可以在别的文件夹,(最好在/usr/local/src下,便于管理),一定要在/usr/local下建立链接指向你的源二进制包
  1. 命令:ln -s /usr/local/src/mysql-VERSION mysql  
  2.     解压:sudo tar zxvf /path/to/your/source.tar.gz     


常见问题3:

  1. air@air:/usr/local/mysql$ sudo scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql  
  2.      Installing MySQL system tables...  
  3.      /usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory  
  4.      Installation of system tables failed!  Examine the logs in  
  5.       /var/lib/mysql for more information.  
  6.       You can try to start the mysqld daemon with:  
  7.        shell> /usr/local/mysql/bin/mysqld --skip-grant & and use the command line tool /usr/local/mysql/bin/mysql to connect to the mysql database and look at the grant tables:  
  8.        shell> /usr/local/mysql/bin/mysql -u root mysql  
  9.         mysql> show tables  
  10.   
  11. Try 'mysqld --help' if you have problems with paths.  Using --log gives you a log in /var/lib/mysql that may be helpful.  
  12. Please consult the MySQL manual section 'Problems running mysql_install_db', and the manual section that describes problems on your OS.  Another information source are the MySQL email archives available at http://lists.mysql.com/.  
  13. Please check all of the above before mailing us!  And remember, if you do mail us, you MUST use the /usr/local/mysql/scripts/mysqlbug script!  
      一般同学解决上面的安装文件夹后,往往还会遇到如上问题,如果你安装完ubuntu后,没有更新库或者安装运行支持库的话。
     主要是少了libaio.so.1这个文件,网上搜一下,或者新立得或者软件中心搜一下,
      知道要安装如下包:
                 libaio1 0.3.109-2ubuntu1,
   安装以下不再报错。



任何问题,欢迎斧正

更多 0
主题推荐
二进制 ubuntu 解决方案 服务器 数据库
博文推荐
android MediaScanner...
Hibernate
数据库语言分类
ubuntu 中找不到libgtk-x1...
sql时间查询
Oracle导入导出数据库
Ubuntu 14.04上安装WineT...
SharePoint部署WSP解决方案包...
查看评论
1楼 stephane 2013-02-01 13:22发表 [回复]
写得太好了~!
发表评论
  • 用 户 名:
  • jiangfuofu555
  • 评论内容:
  • 插入代码
  •   
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
  • 个人资料
    • 访问:64005次
    • 积分:1190分
    • 排名:第11596名
    • 原创:52篇
    • 转载:12篇
    • 译文:0篇
    • 评论:43条
  • 博客专栏
  • 最新评论
  • 推荐文章

公司简介| 招贤纳士| 广告服务| 银行汇款帐号| 联系方式| 版权声明| 法律顾问| 问题报告| 合作伙伴| 论坛反馈
网站客服 杂志客服 微博客服 400-600-2320
京 ICP 证 070598 号
北京创新乐知信息技术有限公司 版权所有
江苏乐知网络技术有限公司 提供商务支持
Copyright © 1999-2014, CSDN.NET, All Rights Reserved  GongshangLogo
更多相关资源: mysql

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值