mysql版本:5.6 【http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.22.tar.gz】
【http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.24.tar.gz】
官方参考:http://dev.mysql.com/doc/refman/5.6/en/installing-source-distribution.html
安装要求:
这里提到的安装要求:
http://dev.mysql.com/doc/refman/5.6/en/source-installation.html
ANSI C++ compiler:GCC 4.2.1 or later
Perl : Perl is needed if you intend to run test scripts 【option】
bison : 2.1 or newer
M4:On OpenSolaris and Solaris Express
而这里的安装要求:
http://dev.mysql.com/doc/internals/en/cmake-prerequisites.html
安装CMake的要求:
CMake:Version 2.6.3 or laterhttp://dev.mysql.com/doc/internals/en/cmake.html
Unix: Compiler and make utility【gcc,make】, curses dev package on Linux
All platforms: bison http://ftp.gnu.org/gnu/bison/bison-2.5.tar.gz
OpenSolaris/Solaris: m4 http://www.gnu.org/software/m4/
大家可以看到两个要求是一致的(废话肯定一致,两个本来说的就是一个事。只是为了避免大家迷惑才两个都拿来说)
安装mysql配置项:
http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html
要注意的就是安装自己用到的字符集,data目录配置,存储引擎的支持【innodb需要明确配置,My_ISAM默认会安装】
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1
字符集 可以在随便一个mysql中执行 SHOW COLLATION 语句,查看所有的。
在正式安装之前,你可能需要安装:ncurses , ncurses-devel
上面有ncurse包:
[root@host ncurse]#./configure
[root@host ncurse]#make&&make install
正式安装:
345 tar zxvf mysql-5.6.22.tar.gz346ls347 cd mysql-5.6.22
348ls349groupadd mysql350 useradd -r -g mysql mysql351cmake .352make353 cmake --help354make clean355rm CMakeCache.txt356make install357 cd /usr/local/mysql/
358 chown -R mysql .359 chgrp -R mysql .360 scripts/mysql_install_db --user=mysql361 chown -R root .362 chown -R mysql data363 bin/mysqld_safe --user=mysql &
364 /usr/local/mysql/bin/mysql -uroot -p365 ls /tmp/
366 ls /tmp/mysql.sock367 bin/mysqld_safe --user=mysql &
368 netstat -an |grep 3306
371 ps aux |grep mysql372 bin/mysqld_safe --user=mysql &
373 less /var/log/mysqld.log374 mkdir /var/run/mysqld375 chown -R mysql /var/run/mysqld376 bin/mysqld_safe --user=mysql &
377 bin/mysql -uroot -p378 ps aux |grep mysql379 netstat -an |grep 3306
380 bin/mysql -uroot -p382 ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock384 bin/mysql -uroot -p397 cp /usr/local/mysql/support-files/mysql.serve /etc/init.d/mysqld398 chkconfig --add mysqld399 chkconfig --level 345mysqld on400service mysqld stop401service mysqld restart402pkill mysql403service mysqld restart404 bin/mysql -uroot -p405halt407 service mysqld start
安装完成。
中间遇到的问题:
安装完成后mysql启动不了:
启动mysql时报错:
Starting mysqld daemon with databasesfrom /var/lib/mysql
STOPPING serverfrom pid file /var/run/mysqld/mysqld.pid071112 00:22:06mysqld ended
查看日志:
#less/var/log/mysqld.log
其中有一段如下:071112 0:22:06 [ERROR] /usr/local/mysql/bin/mysqld: Can't create/write to file'/var/run/mysqld/mysqld.pid'(Errcode: 2)
071112 0:22:06 [ERROR] Can't start server: can't create PID file: No such file or directory071112 00:22:06mysqld ended
#cd/var/run/#ls
mysqld目录不存在,创建。
374 mkdir /var/run/mysqld
375 chown -R mysql /var/run/mysqld
可以正常启动了,但是用客户端连接mysqld 又错:
[root@localhost mysql]# bin/mysqladmin -u root password root
bin/mysqladmin: connect to server at 'localhost'failed
error:'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists![root@localhost mysql]# bin/mysql -u root -p
Enter password:
ERROR2002 (HY000): Can't connect to local MySQL server through socket'/tmp/mysql.sock'(2)
分析:是/tmp/mysql.sock 不存在
由于mysql 默认的mysql.sock 是在/var/lib/mysql/mysql.sock,创建符号连接:
382 ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
再重启,可以了。
如果第一次cmake有问题,需要二次cmake,记得将CMakeCache.txt清理掉,否则新的cmake会不起作用。
1 #!/bin/sh2 # Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB &Detron HB3 # This file is publicdomain and comes with NO WARRANTY of any kind4
5 # MySQL daemon start/stop script.6
7 # Usually this is put in /etc/init.d (at least on machines SYSV R4 based8 # systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.9 # When this is done the mysql server will be started when the machine is
10 # started and shut down when the systems goes down.11
12 # Comments to support chkconfig on RedHat Linux13 # chkconfig: 2345 64 36
14 # description: A very fast and reliable SQL database engine.15
16 # Comments to support LSB init script conventions17 ### BEGIN INIT INFO18 # Provides: mysql19 # Required-Start: $local_fs $network $remote_fs20 # Should-Start: ypbind nscd ldap ntpd xntpd21 # Required-Stop: $local_fs $network $remote_fs22 # Default-Start: 2 3 4 5
23 # Default-Stop: 0 1 6
24 # Short-Description: start and stop MySQL25 # Description: MySQL isa very fast and reliable SQL database engine.26 ### END INIT INFO27
28 # If you install MySQL on some other places than /usr/local/mysql, then you29 # have to do one of the following things for thisscript to work:30 #31 # - Run this script fromwithin the MySQL installation directory32 # - Create a /etc/my.cnf file with the following information:33 # [mysqld]34 # basedir=
35 # - Add the above to any other configuration file (for example ~/.my.ini)36 # and copy my_print_defaults to /usr/bin37 # - Add the path to the mysql-installation-directory to the basedir variable38 # below.39 #40 # If you want to affect other MySQL variables, you should make your changes41 # in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.42
43 # If you change base dir, you must also change datadir. These may get
44 # overwritten by settings inthe MySQL configuration files.45
46 basedir=
47 datadir=
48
49 # Default value, inseconds, afterwhich the script should timeout waiting50 # forserver start.51 # Value here is overriden by value inmy.cnf.52 # 0 means don't wait at all
53 # Negative numbers mean to wait indefinitely54 service_startup_timeout=900
55
56 # Lock directory for RedHat /SuSE.57 lockdir='/var/lock/subsys'
58 lock_file_path="$lockdir/mysql"
59
60 # The following variables are only set forletting mysql.server find things.61
62 # Set some defaults63 mysqld_pid_file_path=
64 if test -z "$basedir"
65 then66 basedir=/usr/local/mysql67 bindir=/usr/local/mysql/bin68 if test -z "$datadir"
69 then70 datadir=/usr/local/mysql/data71 fi72 sbindir=/usr/local/mysql/bin73 libexecdir=/usr/local/mysql/bin74 else
75 bindir="$basedir/bin"
76 if test -z "$datadir"
77 then78 datadir="$basedir/data"
79 fi80 sbindir="$basedir/sbin"
81 libexecdir="$basedir/libexec"
82 fi83
84 # datadir_set is used to determine if datadir was set(and so should be85 # *not* set inside of the --basedir=handler.)86 datadir_set=
87
88 #89 # Use LSB init script functions for printing messages, ifpossible90 #91 lsb_functions="/lib/lsb/init-functions"
92 if test -f $lsb_functions ; then93 . $lsb_functions94 else
95 log_success_msg()96 {97 echo "SUCCESS! $@"
98 }99 log_failure_msg()100 {101 echo "ERROR! $@"
102 }103 fi104
105 PATH="/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin"
106 export PATH107
108 mode=$1# start or stop109
110 [ $# -ge 1 ] &&shift111
112
113 other_args="$*" # uncommon, but needed when called froman RPM upgrade action114 # Expected: "--skip-networking --skip-grant-tables"
115 # They are not checked here, intentionally, as it isthe resposibility116 # of the "spec"file author to give correct arguments only.117
118 case `echo "testing\c"`,`echo -n testing` in
119 *c*,-n*) echo_n= echo_c=;;120 *c*,*) echo_n=-n echo_c=;;121 *) echo_n= echo_c='\c';;122 esac123
124 parse_server_arguments() {125 for arg do
126 case "$arg" in
127 --basedir=*) basedir=`echo "$arg" | sed -e 's/^[^=]*=//'`128 bindir="$basedir/bin"
129 if test -z "$datadir_set"; then130 datadir="$basedir/data"
131 fi132 sbindir="$basedir/sbin"
133 libexecdir="$basedir/libexec"
134 ;;135 --datadir=*) datadir=`echo "$arg" | sed -e 's/^[^=]*=//'`136 datadir_set=1
137 ;;138 --pid-file=*) mysqld_pid_file_path=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;139 --service-startup-timeout=*) service_startup_timeout=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;140 esac141 done142 }143
144 wait_for_pid () {145 verb="$1" # created |removed146 pid="$2" # process ID of the program operating on the pid-file147 pid_file_path="$3"# path to the PID file.148
149 i=0
150 avoid_race_condition="by checking again"
151
152 while test $i -ne $service_startup_timeout ; do
153
154 case "$verb" in
155 'created')156 # wait for a PID-file to pop into existence.157 test -s "$pid_file_path" && i='' && break
158 ;;159 'removed')160 # wait for this PID-file to disappear161 test ! -s "$pid_file_path" && i='' && break
162 ;;163 *)164 echo "wait_for_pid () usage: wait_for_pid created|removed pid pid_file_path"
165 exit 1
166 ;;167 esac168
169 # if server isn't running, then pid-file will never be updated
170 if test -n "$pid"; then171 if kill -0 "$pid" 2>/dev/null; then172 : # the server still runs173 else
174 # The server may have exited between the last pid-file check and now.175 if test -n "$avoid_race_condition"; then176 avoid_race_condition=""
177 continue# Check again.178 fi179
180 # there's nothing that will affect the file.
181 log_failure_msg "The server quit without updating PID file ($pid_file_path)."
182 return 1# not waiting any more.183 fi184 fi185
186 echo $echo_n ".$echo_c"
187 i=`expr $i + 1`188 sleep 1
189
190 done191
192 if test -z "$i"; then193 log_success_msg194 return 0
195 else
196 log_failure_msg197 return 1
198 fi199 }200
201 # Get arguments fromthe my.cnf file,202 # the only group, which is read from now on is[mysqld]203 if test -x ./bin/my_print_defaults204 then205 print_defaults="./bin/my_print_defaults"
206 elif test -x $bindir/my_print_defaults207 then208 print_defaults="$bindir/my_print_defaults"
209 elif test -x $bindir/mysql_print_defaults210 then211 print_defaults="$bindir/mysql_print_defaults"
212 else
213 # Try to find basedir in /etc/my.cnf214 conf=/etc/my.cnf215 print_defaults=
216 if test -r $conf217 then218 subpat='^[^=]*basedir[^=]*=\(.*\)$'
219 dirs=`sed -e "/$subpat/!d" -e 's//\1/'$conf`220 for d in$dirs221 do
222 d=`echo $d | sed -e 's/[ ]//g'`223 if test -x "$d/bin/my_print_defaults"
224 then225 print_defaults="$d/bin/my_print_defaults"
226 break
227 fi228 if test -x "$d/bin/mysql_print_defaults"
229 then230 print_defaults="$d/bin/mysql_print_defaults"
231 break
232 fi233 done234 fi235
236 # Hope it's in the PATH ... but I doubt it
237 test -z "$print_defaults" && print_defaults="my_print_defaults"
238 fi239
240 #241 # Read defaults file from 'basedir'. If there isno defaults file there242 # check if it's in the old (depricated) place (datadir) and read it from there
243 #244
245 extra_args=""
246 if test -r "$basedir/my.cnf"
247 then248 extra_args="-e $basedir/my.cnf"
249 else
250 if test -r "$datadir/my.cnf"
251 then252 extra_args="-e $datadir/my.cnf"
253 fi254 fi255
256 parse_server_arguments `$print_defaults $extra_args mysqld server mysql_server mysql.server`257
258 #259 # Set pid file ifnot given260 #261 if test -z "$mysqld_pid_file_path"
262 then263 mysqld_pid_file_path=$datadir/`hostname`.pid264 else
265 case "$mysqld_pid_file_path" in
266 /*) ;;267 * ) mysqld_pid_file_path="$datadir/$mysqld_pid_file_path" ;;268 esac269 fi270
271 case "$mode" in272 'start')273 # Start daemon274
275 # Safeguard (relative paths, core dumps..)276 cd $basedir277
278 echo $echo_n "Starting MySQL"279 if test -x $bindir/mysqld_safe280 then281 # Give extra arguments to mysqld with the my.cnf file. This script282 # may be overwritten at next upgrade.283 $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &284 wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?285
286 # Make lock for RedHat / SuSE287 if test -w "$lockdir"288 then289 touch "$lock_file_path"290 fi291
292 exit $return_value293 else294 log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)"295 fi296 ;;297
298 'stop')299 # Stop daemon. We use a signal here to avoid having to know the300 # root password.301
302 if test -s "$mysqld_pid_file_path"303 then304 mysqld_pid=`cat "$mysqld_pid_file_path"`305
306 if (kill -0 $mysqld_pid 2>/dev/null)307 then308 echo $echo_n "Shutting down MySQL"309 kill $mysqld_pid310 # mysqld should remove the pid file when it exits, so wait for it.311 wait_for_pid removed "$mysqld_pid" "$mysqld_pid_file_path"; return_value=$?312 else313 log_failure_msg "MySQL server process #$mysqld_pid is not running!"314 rm "$mysqld_pid_file_path"315 fi316
317 # Delete lock for RedHat / SuSE318 if test -f "$lock_file_path"319 then320 rm -f "$lock_file_path"321 fi322 exit $return_value323 else324 log_failure_msg "MySQL server PID file could not be found!"325 fi326 ;;327
328 'restart')329 # Stop the service and regardless of whether it was330 # running or not, start it again.331 if $0 stop $other_args; then332 $0 start $other_args333 else334 log_failure_msg "Failed to stop running server, so refusing to try to start."335 exit 1336 fi337 ;;338
339 'reload'|'force-reload')340 if test -s "$mysqld_pid_file_path" ; then341 read mysqld_pid < "$mysqld_pid_file_path"342 kill -HUP $mysqld_pid && log_success_msg "Reloading service MySQL"343 touch "$mysqld_pid_file_path"344 else345 log_failure_msg "MySQL PID file could not be found!"346 exit 1347 fi348 ;;349 'status')350 # First, check to see if pid file exists351 if test -s "$mysqld_pid_file_path" ; then352 read mysqld_pid < "$mysqld_pid_file_path"353 if kill -0 $mysqld_pid 2>/dev/null ; then354 log_success_msg "MySQL running ($mysqld_pid)"355 exit 0356 else357 log_failure_msg "MySQL is not running, but PID file exists"358 exit 1359 fi360 else361 # Try to find appropriate mysqld process362 mysqld_pid=`pidof $libexecdir/mysqld`363
364 # test if multiple pids exist365 pid_count=`echo $mysqld_pid | wc -w`366 if test $pid_count -gt 1 ; then367 log_failure_msg "Multiple MySQL running but PID file could not be found ($mysqld_pid)"368 exit 5369 elif test -z $mysqld_pid ; then370 if test -f "$lock_file_path" ; then371 log_failure_msg "MySQL is not running, but lock file ($lock_file_path) exists"372 exit 2373 fi374 log_failure_msg "MySQL is not running"375 exit 3376 else377 log_failure_msg "MySQL is running but PID file could not be found"378 exit 4379 fi380 fi381 ;;382 *)383 # usage384 basename=`basename "$0"`385 echo "Usage: $basename {start|stop|restart|reload|force-reload|status} [ MySQL server options ]"386 exit 1387 ;;388 esac389
390 exit 0
mysqld加入服务的脚本
参考:
http://blog.csdn.net/itchiang/article/details/9012493
跟两个无关的yum配置连接,我中间做其他事情用到了。
http://www.cnblogs.com/shuaixf/archive/2011/11/30/2268496.html
http://blog.chinaunix.net/uid-26683523-id-3074744.html
lnmp环境的操作部分:
安装php+nginx:http://www.cnblogs.com/simpman/p/4151662.html
安装mysql:http://www.cnblogs.com/simpman/p/4192942.html
安装php:http://www.cnblogs.com/simpman/p/4196051.html
lnmp环境的理论部分:
FastCgi与PHP-fpm关系[转] 读完本文瞬间明朗了很多 : http://www.cnblogs.com/simpman/p/4151639.html
epoll和select区别:http://www.cnblogs.com/simpman/p/4150005.html