一、非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_passwordport= 3307socket= /home/fc/app/mysql/tmp/3307/mysql.sock# Here follows entries for some specific programs# The MySQL server[mysqld]character-set-server = utf8port= 3307socket= /home/fc/app/mysql/tmp/3307/mysql.sockskip-external-lockingbasedir = /home/fc/app/mysqldatadir = /home/fc/app/mysql/data/3307/log-error = /home/fc/log/3307/mysqld.errpid-file = /home/fc/app/mysql/tmp/3307/mysql.pidkey_buffer_size = 16Mmax_allowed_packet = 1Mtable_open_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8Mmax_connections=200slow_query_log = 1 #{0|1 off|on}slow_query_log_file = /home/fc/log/3307/mysql-slow.loglong_query_time=1#不經常更新的表查詢,緩衝查詢query_cache_type = 1query_cache_size = 10Mgeneral_log = 0general_log_file = /home/fc/log/3307/mysql.logquery_cache_size = 8M#skip-networkingskip-name-resolveskip-innodb-checksums # Replication Master Server (default)# binary logging is required for replicationlog-bin=/home/fc/log/3307/mysql-bin# binary logging format - mixed recommendedbinlog_format=mixedbinlog_cache_size = 1Mmax_binlog_cache_size = 4096Mexpire-logs-days = 8sync_binlog=20# Uncomment the following if you are using InnoDB tablesinnodb_data_home_dir = /home/fc/data/3307/innodb_data_file_path = ibdata1:10M:autoextendinnodb_log_group_home_dir = /home/fc/data/3307/innodb_buffer_pool_size = 800Msort_buffer_size = 5Mtmp_table_size = 64Minnodb_additional_mem_pool_size = 32Minnodb_autoextend_increment = 64 # 預設單位為 MBinnodb_thread_concurrency = 8innodb_log_file_size = 200Minnodb_log_buffer_size = 8Mdefault-storage-engine=innodbinnodb_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 = 50innodb_flush_log_at_trx_commit = 2[mysqldump]quickmax_allowed_packet = 16M[mysqld_safe]log-error=/home/fc/app/mysql/log/3307/mysqld.logpid-file=/home/fc/app/mysql/tmp/3307/mysql.pid[mysql]no-auto-rehashport = 3307socket = /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 = 20Msort_buffer_size = 20Mread_buffer = 2Mwrite_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 installif 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" fielif 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 installelif 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 iselif 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 defaultselse 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串連