设为首页 收藏本站
查看: 1278|回复: 0

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

[复制链接]

尚未签到

发表于 2015-10-14 08:43:54 | 显示全部楼层 |阅读模式





  • DSC0000.jpg

DesignLab
Thinker's Sofa

  • DSC0001.gif 目录视图
  • DSC0002.gif 摘要视图
  • 订阅
云计算大会抢票倒计时    高校俱乐部“我是Coding之星”    【社区之星】专访汪海洋:程序员的程序缘Ubuntu,Mysql二进制安装流程以及常见错误
分类: 服务器调试及管理 LINUX_STEP_BY_STEP文档 2011-11-24 20:171644人阅读 评论(1)收藏 举报mysqlubuntushellairdatabasecommand  前言
  这篇博文是以前写的,有些地方不是很专业,大家凑合看吧,当然按照步骤成功安装MYSQL是不成问题的。
  

  安装环境说明:

系统:ubuntu 11.10
MySql:mysql 5.5.17

  

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

[html] view plaincopyprint?

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

  • cd /etc  
  • rm my.cnf   
  • rm -rf mysql/  
  • cd /  
  • find -name "mysql" -print  
  • cd /etc/apparmor.d/abstractions/  
  • rm -rf mysql   
  •    
以上命令是因为已经安装过mysql,会遗留一些垃圾文件,搜寻一下,全部删除。[html] view plaincopyprint?

  • groupadd mysql  
  • useradd -r -g mysql mysql  
  • cd /usr/local  
  • cd src  
  • ln -s /usr/local/src/mysql-5.5.17-linux2.6-i686/ mysql  
  • cd mysql  
  • chown -R mysql .  
  • chgrp -R mysql .  
  • scripts/mysql_install_db --user=mysql  
  • chown -R root .  
  • chgrp -R mysql .  
  • chown -R root .  
  • chown -R mysql data  
  • ls -l  
  • bin/mysqld_safe --user=mysql &  
  前面可能因为没有chown -R mysql data产生了一系列问题,不知道是不是根本原因所在,先记录一下。执行到这地方,命令行会返回一个进程号,终端提示mysql进程启动,一定没有报错才行。这证明mysql启动了。
   1.2 测试服务
        新开一个终端,进行如下操作:

[html] view plaincopyprint?

  • /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 version5.5.17
  Protocol version10
  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文件,命令如下:

[html] view plaincopyprint?

  • cd /usr/local/mysql  
  • cp support-files/my-medium.cnf /etc/my.cnf  
  现在我们做好了启动服务的准备工作,可以启动了:

[html] view plaincopyprint?

  • 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 plaincopyprint?

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

  • NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL  
  •         SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!  
  • In order to log into MySQL to secure it, we'll need the current  
  • password for the root user.  If you've just installed MySQL, and  
  • you haven't set the root password yet, the password will be blank,  
  • so you should just press enter here.  
  •   
  • Enter current password for root (enter for none):   
  • ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)  
  • Enter current password for root (enter for none):   
  • ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)  
  • Enter current password for root (enter for none):   
  • OK, successfully used password, moving on...  
  •   
  • Setting the root password ensures that nobody can log into the MySQL  
  • root user without the proper authorisation.  
  • Set root password? [Y/n] y  
  • New password:   
  • Re-enter new password:   
  • Password updated successfully!  
  • Reloading privilege tables..  
  • ... Success!  
  • By default, a MySQL installation has an anonymous user, allowing anyone  
  • to log into MySQL without having to have a user account created for  
  • them.  This is intended only for testing, and to make the installation  
  • go a bit smoother.  You should remove them before moving into a  
  • production environment.  
  • Remove anonymous users? [Y/n] y  
  •   ... Success!  
  • Normally, root should only be allowed to connect from 'localhost'.  This  
  • ensures that someone cannot guess at the root password from the network.  
  •    Disallow root login remotely? [Y/n] y  
  •   ... Success!  
  • By default, MySQL comes with a database named 'test' that anyone ca  
  • access.  This is also intended only for testing, and should be removed  
  • before moving into a production environment.  
  • Remove test database and access to it? [Y/n] y  
  • - Dropping test database...  
  • ERROR 1010 (HY000) at line 1: Error dropping database (can't rmdir './test/', errno: 17)  
  • ... Failed!  Not critical, keep moving...  
  •   - Removing privileges on test database...  
  •    ... Success!  
  • Reloading the privilege tables will ensure that all changes made so far  
  • will take effect immediately.  
  •    Reload privilege tables now? [Y/n] y  
  •   ... Success!  
  •   
  • Cleaning up...  
  •    All done!  If you've completed all of the above steps, your MySQL  
  •    installation should now be secure.  
  •   
  •    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 plaincopyprint?

  • $ sudo nano /etc/profile  
  添加如下语句:
[html] view plaincopyprint?

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

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

[html] view plaincopyprint?

  • /usr/local/mysql/bin/mysqld //启动Mysql服务   
  • /usr/local/mysql/bin/mysql -u root //访问Mysql服务器  
  • /usr/local/mysql/bin/mysqladmin -u root -p shutdown   //关闭mysql服务器  
   最好应该使其运行在后台:
[html] view plaincopyprint?

  • /usr/local/mysql/bin/mysqld &  
   让服务开机自动运行
[html] view plaincopyprint?

  • cp /usr/local/mysql/support-files/my.server /etc/init.d/mysqld  
  • sudo update-rc.d mysqld default  
     把mysqld加入到服务中,重新启动机器即可
     当然以后启动可以直接输入
[html] view plaincopyprint?

  • /etc/init.d/mysqld restart|start  
      到此,MYSQL的安装工作基本已经做完了。

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

  • air@air:/usr/local/mysql/bin$ sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &  
  • [1] 6378  
  • air@air:/usr/local/mysql/bin$ 111116 11:58:56 mysqld_safe Logging to '/var/log/mysql/error.log'.  
  • touch: 无法创建"/var/log/mysql/error.log": 没有那个文件或目录  
  • chown: 无法访问"/var/log/mysql/error.log": 没有那个文件或目录  
  • 111116 11:58:56 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql  
  • /usr/local/mysql/bin/mysqld_safe: 107: /usr/local/mysql/bin/mysqld_safe: cannot create /var/log/mysql/error.log: Directory nonexistent  
  • /usr/local/mysql/bin/mysqld_safe: 1: eval: cannot create /var/log/mysql/error.log: Directory nonexistent  
  • 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 plaincopyprint?

  • air@air:/usr/local/mysql$ scripts/mysql_install_db --user=mysql  
  •   FATAL ERROR: Could not find mysqld  
  •            The following directories were searched:  
  •            /usr/libexec  
  •             /usr/sbin  
  •             /usr/bin  
  • If you compiled from source, you need to run 'make install' to copy the software into the correct location ready for operation.  
  • 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 plaincopyprint?

  • 命令:ln -s /usr/local/src/mysql-VERSION mysql  
  •     解压:sudo tar zxvf /path/to/your/source.tar.gz     
  

  常见问题3:
[html] view plaincopyprint?

  • air@air:/usr/local/mysql$ sudo scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql  
  •      Installing MySQL system tables...  
  •      /usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory  
  •      Installation of system tables failed!  Examine the logs in  
  •       /var/lib/mysql for more information.  
  •       You can try to start the mysqld daemon with:  
  •        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:  
  •        shell> /usr/local/mysql/bin/mysql -u root mysql  
  •         mysql> show tables  
  •   
  • Try 'mysqld --help' if you have problems with paths.  Using --log gives you a log in /var/lib/mysql that may be helpful.  
  • 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/.  
  • 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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-126459-1-1.html 上篇帖子: 2012 “社区活动”博客专栏未收录活动 下篇帖子: C#开源资源超级大汇总
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表