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

编程入门 行业动态 更新时间:2024-10-10 08:22:02

Ubuntu,Mysql二进制安装<a href=https://www.elefans.com/category/jswz/34/1770115.html style=流程以及常见错误"/>

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





DesignLab

Thinker's Sofa

  • 目录视图
  • 摘要视图
  • 订阅
云计算大会抢票倒计时     高校俱乐部“我是Coding之星”     【社区之星】专访汪海洋:程序员的程序缘

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

分类: 服务器调试及管理 LINUX_STEP_BY_STEP文档 2011-11-24 20:17 1644人阅读 评论(1) 收藏 举报 mysql ubuntu shell air database command

前言

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


安装环境说明:


系统:ubuntu 11.10
MySql:mysql 5.5.17


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

[html] view plain copy print ?
  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-mediumf /etc/myf  
  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用户密码就可以了

      附命令记录:      

[html] view plain copy print ?
  1. cd /etc  
  2. rm myf   
  3. rm -rf mysql/  
  4. cd /  
  5. find -name "mysql" -print  
  6. cd /etc/apparmor.d/abstractions/  
  7. rm -rf mysql   
  8.    
以上命令是因为已经安装过mysql,会遗留一些垃圾文件,搜寻一下,全部删除。 [html] view plain copy print ?
  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 测试服务
        新开一个终端,进行如下操作:

[html] view plain copy print ?
  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文件夹下,命名为myf文件,命令如下:

[html] view plain copy print ?
  1. cd /usr/local/mysql  
  2. cp support-files/my-mediumf /etc/myf  

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

[html] view plain copy print ?
  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安全配置
      现在我们服务起来了,但是密码等都没有设置,接下来我们可以运行如下命令:

[html] view plain copy print ?
  1. root@air:/usr/local/mysql# bin/mysql_secure_installation   
  返回如下:我列举出来,其实可以按着INSTALL-BINARY说明文件中的两条语句手工设置密码,删除TEST数据库,和匿名用户等操作,(从安全性讲,一定要做如上动作)但是推荐还是用上面的语句一并设置。
[html] view plain copy print ?
  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):

[html] view plain copy print ?
  1. $ sudo nano /etc/profile  

添加如下语句:

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

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

[html] view plain copy print ?
  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服务器  
   最好应该使其运行在后台:
[html] view plain copy print ?
  1. /usr/local/mysql/bin/mysqld &  
   让服务开机自动运行
[html] view plain copy print ?
  1. cp /usr/local/mysql/support-files/my.server /etc/init.d/mysqld  
  2. sudo update-rc.d mysqld default  
     把mysqld加入到服务中,重新启动机器即可
     当然以后启动可以直接输入 
[html] view plain copy print ?
  1. /etc/init.d/mysqld restart|start  
      到此,MYSQL的安装工作基本已经做完了。

几个常见错误:

常见错误1:
第一次在普通用户权限下安装,可能因为权限的问题,并丢失了一个操作步骤,所以导致安装成功,但是每次启动总报错:
[plain] view plain copy print ?
  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:

[html] view plain copy print ?
  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下建立链接指向你的源二进制包
[plain] view plain copy print ?
  1. 命令:ln -s /usr/local/src/mysql-VERSION mysql  
  2.     解压:sudo tar zxvf /path/to/your/source.tar.gz     


常见问题3:

[html] view plain copy print ?
  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 /.  
  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网站的观点或立场
核心技术类目
全部主题 Java VPN Android iOS ERP IE10 Eclipse CRM JavaScript Ubuntu NFC WAP jQuery 数据库 BI HTML5 Spring Apache Hadoop .NET API HTML SDK IIS Fedora XML LBS Unity Splashtop UML components Windows Mobile Rails QEMU KDE Cassandra CloudStack FTC coremail OPhone CouchBase 云计算 iOS6 Rackspace Web App SpringSide Maemo Compuware 大数据 aptech Perl Tornado Ruby Hibernate ThinkPHP Spark HBase Pure Solr Angular Cloud Foundry Redis Scala Django Bootstrap
  • 个人资料

  • altand
    • 访问:64005次
    • 积分:1190分
    • 排名:第11596名
    • 原创:52篇
    • 转载:12篇
    • 译文:0篇
    • 评论:43条
  • 博客专栏
  • Linux系统简明教程

    文章:8篇

    阅读:4529
  • 文章分类
  • 服务器调试及管理(20)
  • 编程技术与思想(6)
  • LINUX_STEP_BY_STEP文档(11)
  • WEB DESIGN(7)
  • SHELL_SCRIPT(10)
  • C/C++(4)
  • Linux(9)
  • 阅读排行
  • 解决tomcat报错 java.ConnectException: Connection refused问题的方法(9313)
  • HowTo:Ubuntu11.10 安装Oracle10g备忘录(3155)
  • Ubuntu上配置SVN,Apache服务以及常见问题解决方法(3151)
  • svn update报no such revision * 的解决方法(2452)
  • 关于Tomcat服务器出现error occurred during initialization of vm ,noclassdeffounderror错误的问题(2402)
  • svn中import 从本地编码转换到UTF8失败以及checkout到本地后svn 工作副本已经锁定,尚未纳入版本控制解决(2200)
  • Linux排版利器-TeX可视化工具LyX中文编辑环境安装配置指南(2152)
  • HOWTO:Mantis Bug Tracker Step-by-Step安装说明(1897)
  • Ubuntu,Mysql二进制安装流程以及常见错误(1644)
  • 人类已经无法阻止理工科宅男了~~~(Gnuplot 和 Matplotlib使用小节)(1616)
  • 评论排行
  • HowTo:Ubuntu11.10 安装Oracle10g备忘录(9)
  • 计算机本科开设课程示意图---解答目前大学开设这些课程的原因(9)
  • LINUX系统学习系列---备忘录(7)
  • python学习备忘录--1(2)
  • JS倒计时、跳转模块以及JSP中比较日期跳转模块(2)
  • 心情随笔3(2)
  • OpenAFS服务器重新安装流程(2)
  • svn中import 从本地编码转换到UTF8失败以及checkout到本地后svn 工作副本已经锁定,尚未纳入版本控制解决(2)
  • 解决tomcat报错 java.ConnectException: Connection refused问题的方法(2)
  • Jquery学习备忘录(1)
  • 文章存档
    • 2014年02月(1)
    • 2013年07月(1)
    • 2013年05月(4)
    • 2013年02月(2)
    • 2012年09月(5) 展开
  • 最新评论
  • HowTo:Ubuntu11.10 安装Oracle10g备忘录

    altand:@tombwen:可以给个邮箱撒?

  • HowTo:Ubuntu11.10 安装Oracle10g备忘录

    altand:@tombwen:好久前的写的,都已经忘了,不过高手就是高手,有空指点指点啊,哈哈,

  • HowTo:Ubuntu11.10 安装Oracle10g备忘录

    tombwen:关于3.4,在那个错误执行的脚本中,在gcc的引用的东西中国添加LOCALNETLIBS中的like...

  • HowTo:Ubuntu11.10 安装Oracle10g备忘录

    altand:@tombwen:果然还是有高手的,这个当时弄了很长时间,翻了不少资料,还是没有完美解决,多谢啊

  • HowTo:Ubuntu11.10 安装Oracle10g备忘录

    tombwen:关于3.3,是因为库的引用顺序有问题,按如下修改就ok了LSNRCTL_LINKLINE=$(LIN...

  • 解决tomcat报错 java.ConnectException: Connection refused问题的方法

    justgou:学习

  • 解决tomcat报错 java.ConnectException: Connection refused问题的方法

    varyli:恩,不错!

  • svn中import 从本地编码转换到UTF8失败以及checkout到本地后svn 工作副本已经锁定,尚未纳入版本控制解决

    yudca:果然删除了log文件,问题解决了,谢谢楼主

  • LINUX系统学习系列---备忘录

    张德裕:赞~~~~

  • LINUX系统笔记2---系统的引导

    平原上的星星:作者写的很用心,佩服!

  • 推荐文章

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

更多推荐

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

本文发布于:2024-02-07 04:01:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1753075.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:流程   错误   常见   Ubuntu   Mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!