zoukankan      html  css  js  c++  java
  • MySQL启动时必需/usr/local/mysql目录的问题解决方法

    在文章《Ubuntu 12.04 下安装MySQL 5.5.25》中,介绍了我安装MySQL的整个过程。由于我的MySQL不是安装在标准的/usr/local/mysql目录,而是安装在/usr/local/development/mysql-5.5.25目录,导致在启动MySQL服务时报告找不到/usr/local/mysql目录的错误。最后我就创建了符号链/usr/local/mysql链接到/usr/local/development/mysql-5.5.25,解决了服务启动不了的问题。

    为什么会出现此问题呢?我们可以打开mysql.server脚本文件,里面有这样的代码:

    # If you install MySQL on some other places than /usr/local/mysql, then you
    # have to do one of the following things for this script to work:
    #
    # - Run this script from within the MySQL installation directory
    # - Create a /etc/my.cnf file with the following information:
    #   [mysqld]
    #   basedir=<path-to-mysql-installation-directory>
    # - Add the above to any other configuration file (for example ~/.my.ini)
    #   and copy my_print_defaults to /usr/bin
    # - Add the path to the mysql-installation-directory to the basedir variable
    #   below.
    #
    # If you want to affect other MySQL variables, you should make your changes
    # in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
    
    # If you change base dir, you must also change datadir. These may get
    # overwritten by settings in the MySQL configuration files.
    
    basedir=
    datadir=
    
    # The following variables are only set for letting mysql.server find things.
    
    # Set some defaults
    mysqld_pid_file_path=
    if test -z "$basedir"
    then
      basedir=/usr/local/mysql
      bindir=/usr/local/mysql/bin
      if test -z "$datadir"
      then
        datadir=/usr/local/mysql/data
      fi
      sbindir=/usr/local/mysql/bin
      libexecdir=/usr/local/mysql/bin
    else
      bindir="$basedir/bin"
      if test -z "$datadir"
      then
        datadir="$basedir/data"
      fi
      sbindir="$basedir/sbin"
      libexecdir="$basedir/libexec"
    fi

    也就是说,/usr/local/mysql目录是它的默认安装目录。要解决此问题,需要有两个步骤。

    步骤一:创建/etc/my.cnf文件,里面包含basedir目录设定。

    cd /usr/local/development/mysql-5.5.25/support-files
    sudo cp my-medium.cnf my.cnf
    cd /etc
    sudo ln -s /usr/local/development/mysql-5.5.25/support-files/my.cnf

    然后将basedir=/usr/local/development/mysql-5.5.25这一条指令放到my.cnf文件的mysqld段。

    # The MySQL server
    [mysqld]
    
    ......
    
    basedir=/usr/local/development/mysql-5.5.25

    步骤二:将mysql目录下的bin/my_print_defaults链接到/usr/bin目录下。

    cd /usr/bin
    sudo ln -s /usr/local/development/mysql-5.5.25/bin/my_print_defaults

    为什么需要my_print_defaults呢?这是因为mysql.server执行时就是通过my_print_defaults来读取my.cnf配置变量的。

    完成上面两个步骤后,删除/usr/local/mysql,也应该是可以正常启动和停止mysql服务的。

  • 相关阅读:
    spark学习进度9
    spark学习进度8-scrapy框架的安装与使用
    spark学习进度7-Python爬取大学排名实例
    spark学习进度6-Python爬取数据的四个简单实例
    spark学习进度5-利用开发工具IntelliJ IDEA编写Spark应用程序(Scala+Maven)
    Scala官网下载不下来问题-已解决
    spark学习进度4
    大数据学习总结07
    大数据学习总结06
    大数据学习总结05
  • 原文地址:https://www.cnblogs.com/eastson/p/2545531.html
Copyright © 2011-2022 走看看