mysql二进制非root用户安装后启动mysqld的路径不对的问题

一、非root用户安装二进制mysql分发版

创建用户 

 >useradd fc

>passwd fc

enter password:

...


以fc登录,上传二进制mysql版本,我的是mysql 32位的mysql-5.1.57-linux-i686-glibc23.tar.gz

解压后,创建权限表

]$ scripts/mysql_install_db --basedir=/home/fc/app/mysql  --datadir=/home/fc/app/mysql/data/3307 --user=fc 

  (注意:后面的参数一定要指定 ,另外最好是 scripts/mysql_install_db 这样一起运行,官方文档也是这样,免得出错,后面就有这个原因导致启动出错的)

权限表也初始化完了,然后就是指定配置文件my.cnf  我放在$HOME目录下:

# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password	= your_password
port		= 3307
socket		= /home/fc/app/mysql/tmp/3307/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
character-set-server = utf8
port		= 3307
socket		= /home/fc/app/mysql/tmp/3307/mysql.sock
skip-external-locking
basedir = /home/fc/app/mysql
datadir = /home/fc/app/mysql/data/3307/
log-error = /home/fc/log/3307/mysqld.err
pid-file = /home/fc/app/mysql/tmp/3307/mysql.pid
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
max_connections=200

slow_query_log = 1                                     #{0|1  off|on}
slow_query_log_file = /home/fc/log/3307/mysql-slow.log
long_query_time=1

#不经常更新的表查询,缓存查询
query_cache_type = 1
query_cache_size = 10M

general_log = 0
general_log_file = /home/fc/log/3307/mysql.log

query_cache_size = 8M

#skip-networking
skip-name-resolve
skip-innodb-checksums 

# Replication Master Server (default)
# binary logging is required for replication
log-bin=/home/fc/log/3307/mysql-bin

# binary logging format - mixed recommended
binlog_format=mixed
binlog_cache_size = 1M
max_binlog_cache_size = 4096M
expire-logs-days = 8
sync_binlog=20


# Uncomment the following if you are using InnoDB tables
innodb_data_home_dir = /home/fc/data/3307/
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /home/fc/data/3307/
innodb_buffer_pool_size = 800M
sort_buffer_size = 5M
tmp_table_size = 64M
innodb_additional_mem_pool_size = 32M
innodb_autoextend_increment = 64  # 默认单位为 MB

innodb_thread_concurrency = 8
innodb_log_file_size = 200M
innodb_log_buffer_size = 8M
default-storage-engine=innodb
innodb_flush_log_at_trx_commit = 1

# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

innodb_flush_log_at_trx_commit = 2

[mysqldump]
quick
max_allowed_packet = 16M

[mysqld_safe]
log-error=/home/fc/app/mysql/log/3307/mysqld.log
pid-file=/home/fc/app/mysql/tmp/3307/mysql.pid

[mysql]
no-auto-rehash
port            = 3307
socket          = /home/fc/app/mysql/tmp/3307/mysql.sock
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

好了,一切都准备好了,可以启动了

二、启动mysqld进程

进入basedir目录fc/app/mysql

mysql]$ cd bin

bin]$ mysqld_safe --defaults-file=~/my.cnf &

启动成功了,查看进程

ps -ef | grep mysqld 发现问题了

fc    7780  7582 24 16:42 pts/10   00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=~/my.cnf --basedir=/home/fc/app/mysql --datadir=/home/fc/app/mysql/data/3307/ --log-error=/home/fc/app/mysql/log/3307/mysqld.log --pid-file=/home/fc/app/mysql/tmp/3307/mysql.pid --socket=/home/fc/app/mysql/tmp/3307/mysql.sock --port=3307

发现没有,虽然进入的fc/app/mysql/bin目录下启动的mysqld程序,但是查找进程时候却是运行的/usr/lcoal/mysql下的mysqld,这是为什么呢?

查找了很久的参数,都发现没有配置错误,始终不得其解,如是换了种启动方式:

进入base目录fc/app/mysql

mysql]$ bin/msyqld_safe --defaults-file=~/my.cnf &

这样启动后再查找mysqld进程,一切就正常了,这是为什么呢?


我自己想的原因可能是:

mysqld_safe本身就是mysqld的守护进程,它本身也是一个shell脚本,在脚本中,默认的basedir就是:usr/local/mysql,我们在启动mysqld的时候如果进入了bin目录,则在这个守护进程中是找不到该目录的,如是就去自动匹配/usr/local/mysql/这个目录,刚好我也在这个目录之前装过mysql,于是系统就自动匹配了这个mysqld程序,运行起来了。

我们查看下mysqld_safe的一段shell代码:

MY_PWD=`pwd`
# Check for the directories we would expect from a binary release install
if test -n "$MY_BASEDIR_VERSION" -a -d "$MY_BASEDIR_VERSION"
then
  # BASEDIR is already overridden on command line.  Do not re-set.
 
  # Use BASEDIR to discover le.
  if test -x "$MY_BASEDIR_VERSION/libexec/mysqld"
  then
    ledir="$MY_BASEDIR_VERSION/libexec"
  elif test -x "$MY_BASEDIR_VERSION/sbin/mysqld"
  then
    ledir="$MY_BASEDIR_VERSION/sbin"
  else
    ledir="$MY_BASEDIR_VERSION/bin"
  fi
elif test -f "$relpkgdata"/english/errmsg.sys -a -x "$MY_PWD/bin/mysqld"
then
  MY_BASEDIR_VERSION="$MY_PWD"          # Where bin, share and data are
  ledir="$MY_PWD/bin"                   # Where mysqld is
# Check for the directories we would expect from a source install
elif test -f "$relpkgdata"/english/errmsg.sys -a -x "$MY_PWD/libexec/mysqld"
then
  MY_BASEDIR_VERSION="$MY_PWD"          # Where libexec, share and var are
  ledir="$MY_PWD/libexec"               # Where mysqld is
elif test -f "$relpkgdata"/english/errmsg.sys -a -x "$MY_PWD/sbin/mysqld"
then
  MY_BASEDIR_VERSION="$MY_PWD"          # Where sbin, share and var are
  ledir="$MY_PWD/sbin"                  # Where mysqld is
# Since we didn't find anything, used the compiled-in defaults
else
  MY_BASEDIR_VERSION='/usr/local/mysql'
  ledir='/usr/local/mysql/bin'
fi

如果我们进入了bin目录:
ledir 跑到 else
MY_BASEDIR_VERSION='/usr/local/mysql'
ledir='/usr/local/mysql/bin'
正常的情况下应该是:"$MY_PWD/bin/mysqld" 
问题是没有cd到 mysql basedir 的情况下,mysql会从/usr/loca/mysql/bin/mysqld启动


PS:附连接的问题


由于我们启动是按照socket启动的,所以我们在连接时候如果使用的是localhost或者缺省的状态去连接mysql,则我们连接必须使用指定的socket全路径去连接。不然系统会默认的去寻找/tmp/mysql.socket这个,找不到则报错;
当然我们还可以使用-h 127.0.0.1 的方式来连接,这样就不需要指定 -S socket路径了;


mysql连接的方式有2种,一种是通过socket,一种是通过tcp/ip连接





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章