程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> mysql二進制非root用戶安裝後啟動mysqld的路徑不對的問題

mysql二進制非root用戶安裝後啟動mysqld的路徑不對的問題

編輯:MySQL綜合教程


mysql二進制非root用戶安裝後啟動mysqld的路徑不對的問題   一、非root用戶安裝二進制mysql分發版   創建用戶     >useradd fc   www.2cto.com   >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目錄下:
  [python]  # Example MySQL config file for medium systems.   #    www.2cto.com   # 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       www.2cto.com   # 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       www.2cto.com   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       www.2cto.com   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       www.2cto.com   [mysqlhotcopy]   interactive-timeout     好了,一切都准備好了,可以啟動了 二、啟動mysqld進程 進入basedir目錄fc/app/mysql mysql]$ cd bin bin]$ mysqld_safe --defaults-file=~/my.cnf & 啟動成功了,查看進程   ps -ef | grep mysqld 發現問題了 [plain]  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代碼: [python]  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    www.2cto.com   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啟動   www.2cto.com   PS:附連接的問題   由於我們啟動是按照socket啟動的,所以我們在連接時候如果使用的是localhost或者缺省的狀態去連接mysql,則我們連接必須使用指定的socket全路徑去連接。不然系統會默認的去尋找/tmp/mysql.socket這個,找不到則報錯; 當然我們還可以使用-h 127.0.0.1 的方式來連接,這樣就不需要指定 -S socket路徑了;   mysql連接的方式有2種,一種是通過socket,一種是通過tcp/ip連接 [plain]  <pre name="code" class="python"></pre>   <pre></pre>   <pre></pre>   <pre></pre>       作者 林志

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved