MySQL启动时必需到usr/local/mysql目录的问题解决方法

之前我安装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服务的。

原文地址:http://blog.51cto.com/13687553/2156898

时间: 2024-10-10 11:06:21

MySQL启动时必需到usr/local/mysql目录的问题解决方法的相关文章

启动mysql 失败,“Warning:The /usr/local/mysql/data directory is not owned by the &#39;mysql&#39; or &#39;_mysql&#39; ”

一.Mac OS X的升级或其他原因可能会导致MySQL启动或开机自动运行时 在MySQL操作面板上会提示“Warning:The /usr/local/mysql/data directory is not owned by the 'mysql' or '_mysql' ”, 这应该是某种情况下导致/usr/local/mysql/data的宿主发生了改变, 只需要运行“sudo chown -R mysql /usr/local/mysql/data”即可 mac 下面运行 “sudo c

mysqld_safe启动报错 mysqld_safe The file /usr/local/mysql/bin/mysqld does not exist or is not executable

报错(如下),但是使用mysqld直接启动没有问题. 150718 00:03:38 mysqld_safe Logging to '/var/log/mysqld.log'. 150718 00:03:38 mysqld_safe The file /usr/local/mysql/bin/mysqld does not exist or is not executable. Please cd to the mysql installation directory and restart t

mariadb 二进制启动报错,Can&#39;t find messagefile &#39;/usr/local/mysql/share/mysql/errmsg.sys&#39;

直接看操作步骤 [[email protected] share]# mysqld_safe --defaults-file=/etc/my.cnf & [1] 3482 [[email protected] share]# 170103 18:48:58 mysqld_safe Logging to '/log/mysql/error.log'. [1]+  Done                    mysqld_safe --defaults-file=/etc/my.cnf [[em

启动 mysql 失败 Warning:The /usr/local/mysql/data directory is not owned by the &#39;mysql&#39; or &#39;_mysql&#39;

Warning:The /usr/local/mysql/data directory is not owned by the 'mysql' or '_mysql' 这应该是某种情况下导致/usr/local/mysql/data的宿主发生了改变. 解决方法:打开终端运行 sudo chown -R mysql /usr/local/mysql/data 即可. mac 下运行  sudo chown -R  _mysql:wheel  /usr/local/mysql/data . -c 显

Linux Centos 启动mysql ERROR * The server quit without updating PID file (/usr/local/mysql/data/mysql.pid).

做了一些尝试:比如kill -9 进程id  发现根本就杀不死. 查看ERROR.LOG 2015-12-07 18:50:08 29710 [ERROR] /usr/local/mysql/bin/mysqld: unknown variable 'scripts/mysql_install_db --user=mysql' 第一感觉:百度了下.大部分都是说安装的时候有这个问题:感觉场景不太一样:回到原点继续想: scripts/mysql_install_db --user=mysql --

linux下安装mysql问题总结(一)mysqld_safe mysqld from pid file /usr/local/mysql/data/mysql.pid ended

linux下安装mysql数据库 linux版本:CentOS release 6.8 (Final) mysql版本:mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz 在安装数据库过成中,输入启动mysql命令:/usr/local/mysql/support-files/mysql.server start 报错信息如图: 进入/usr/local/mysql/data目录下查看报错日志: 经在网上查找解决方案,折腾了一翻还是不行,后来发现在初始化数据库步骤

编译安装或者mysql启动时遇到的错误小记

编译安装遇到的错误:进入mysql目录 [[email protected] software]# cd mysql-5.6.19 [[email protected] mysql-5.5.11]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/mydb -DMYSQL_UNIX_ADDR=/home/mydb/mysqld.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -

解决:error: Cannot find libmysqlclient_r under /usr/local/mysql.

转 解决:error: Cannot find libmysqlclient_r under /usr/local/mysql. 配置php的时候出现以下问题解决方案 checking for MySQL support... yeschecking for specified location of the MySQL UNIX socket...nochecking for MySQL UNIX socket location... noconfigure: error: Cannot fi

Starting MySQL.. ERROR! The server quit without updating PID file (/usr/local/mysql/data/vm10-0-0-19

输入:service mysqld start 报错: Starting MySQL.. ERROR! The server quit without updating PID file (/usr/local/mysql/data/vm10-0-0-19.ksc.com.pid). 解决: ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ 参考