码迷,mamicode.com
首页 > 数据库 > 详细

linux通过tar.gz源码包安装mysql

时间:2014-12-30 11:15:45      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:

mysql版本:5.6 【http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.22.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

需要工具:CMake  http://www.cmake.org

make工具:http://www.gnu.org/software/make/   GNU make 3.75 or newer 

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 later    http://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默认会安装】

字符集 可以在随便一个mysql中执行 SHOW COLLATION 语句,查看所有的。

 

正式安装:

  345  tar zxvf mysql-5.6.22.tar.gz 
  346  ls
  347  cd mysql-5.6.22
  348  ls
  349  groupadd mysql
  350  useradd -r -g mysql mysql
  351  cmake .
  352  make
  353  cmake --help
  354  make clean
  355  rm CMakeCache.txt 
  356  make install
  357  cd /usr/local/mysql/
  358  chown -R mysql .
  359  chgrp -R mysql .
  360  scripts/mysql_install_db  --user=mysql
  361  chown -R root .
  362  chown -R mysql data
  363  bin/mysqld_safe --user=mysql &
  364  /usr/local/mysql/bin/mysql -uroot -p
  365  ls /tmp/
  366  ls /tmp/mysql.sock
  367  bin/mysqld_safe --user=mysql &
  368  netstat -an |grep 3306
  371  ps aux |grep mysql
  372  bin/mysqld_safe --user=mysql &
  373  less /var/log/mysqld.log
  374  mkdir /var/run/mysqld
  375  chown -R mysql /var/run/mysqld
  376  bin/mysqld_safe --user=mysql &
  377  bin/mysql -uroot -p
  378  ps aux |grep mysql
  379  netstat -an |grep 3306
  380  bin/mysql -uroot -p
  382  ln -s /var/lib/mysql/mysql.sock  /tmp/mysql.sock
  384  bin/mysql -uroot -p
  397  cp /etc/init.d/mysql.server /etc/init.d/mysqld
  398  chkconfig --add mysqld
  399  chkconfig --level 345 mysqld on
  400  service mysqld stop
  401  service mysqld restart
  402  pkill mysql
  403  service mysqld restart
  404  bin/mysql -uroot -p
  405  halt
  407  service mysqld start

安装完成。

中间遇到的问题:

安装完成后mysql启动不了:

启动mysql时报错:

Starting mysqld daemon with databases from /var/lib/mysql
STOPPING server from pid file /var/run/mysqld/mysqld.pid
071112 00:22:06 mysqld ended
查看日志:
#less /var/log/mysqld.log
其中有一段如下:


071112 0:22:06 [ERROR] /usr/local/mysql/bin/mysqld: Cant create/write to file /var/run/mysqld/mysqld.pid (Errcode: 2)
071112 0:22:06 [ERROR] Cant start server: cant create PID file: No such file or directory
071112 00:22:06 mysqld 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: Cant 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:
ERROR 2002 (HY000): Cant 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

再重启,可以了。

 

技术分享
  1 #!/bin/sh
  2 # Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
  3 # This file is public domain and comes with NO WARRANTY of any kind
  4 
  5 # MySQL daemon start/stop script.
  6 
  7 # Usually this is put in /etc/init.d (at least on machines SYSV R4 based
  8 # 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 Linux
 13 # chkconfig: 2345 64 36
 14 # description: A very fast and reliable SQL database engine.
 15 
 16 # Comments to support LSB init script conventions
 17 ### BEGIN INIT INFO
 18 # Provides: mysql
 19 # Required-Start: $local_fs $network $remote_fs
 20 # Should-Start: ypbind nscd ldap ntpd xntpd
 21 # Required-Stop: $local_fs $network $remote_fs
 22 # Default-Start:  2 3 4 5
 23 # Default-Stop: 0 1 6
 24 # Short-Description: start and stop MySQL
 25 # Description: MySQL is a very fast and reliable SQL database engine.
 26 ### END INIT INFO
 27  
 28 # If you install MySQL on some other places than /usr/local/mysql, then you
 29 # have to do one of the following things for this script to work:
 30 #
 31 # - Run this script from within the MySQL installation directory
 32 # - Create a /etc/my.cnf file with the following information:
 33 #   [mysqld]
 34 #   basedir=<path-to-mysql-installation-directory>
 35 # - Add the above to any other configuration file (for example ~/.my.ini)
 36 #   and copy my_print_defaults to /usr/bin
 37 # - Add the path to the mysql-installation-directory to the basedir variable
 38 #   below.
 39 #
 40 # If you want to affect other MySQL variables, you should make your changes
 41 # 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 in the MySQL configuration files.
 45 
 46 basedir=
 47 datadir=
 48 
 49 # Default value, in seconds, afterwhich the script should timeout waiting
 50 # for server start. 
 51 # Value here is overriden by value in my.cnf. 
 52 # 0 means dont wait at all
 53 # Negative numbers mean to wait indefinitely
 54 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 for letting mysql.server find things.
 61 
 62 # Set some defaults
 63 mysqld_pid_file_path=
 64 if test -z "$basedir"
 65 then
 66   basedir=/usr/local/mysql
 67   bindir=/usr/local/mysql/bin
 68   if test -z "$datadir"
 69   then
 70     datadir=/usr/local/mysql/data
 71   fi
 72   sbindir=/usr/local/mysql/bin
 73   libexecdir=/usr/local/mysql/bin
 74 else
 75   bindir="$basedir/bin"
 76   if test -z "$datadir"
 77   then
 78     datadir="$basedir/data"
 79   fi
 80   sbindir="$basedir/sbin"
 81   libexecdir="$basedir/libexec"
 82 fi
 83 
 84 # datadir_set is used to determine if datadir was set (and so should be
 85 # *not* set inside of the --basedir= handler.)
 86 datadir_set=
 87 
 88 #
 89 # Use LSB init script functions for printing messages, if possible
 90 #
 91 lsb_functions="/lib/lsb/init-functions"
 92 if test -f $lsb_functions ; then
 93   . $lsb_functions
 94 else
 95   log_success_msg()
 96   {
 97     echo " SUCCESS! $@"
 98   }
 99   log_failure_msg()
100   {
101     echo " ERROR! $@"
102   }
103 fi
104 
105 PATH="/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin"
106 export PATH
107 
108 mode=$1    # start or stop
109 
110 [ $# -ge 1 ] && shift
111 
112 
113 other_args="$*"   # uncommon, but needed when called from an RPM upgrade action
114            # Expected: "--skip-networking --skip-grant-tables"
115            # They are not checked here, intentionally, as it is the resposibility
116            # 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 esac
123 
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"; then
130               datadir="$basedir/data"
131             fi
132             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     esac
141   done
142 }
143 
144 wait_for_pid () {
145   verb="$1"           # created | removed
146   pid="$2"            # process ID of the program operating on the pid-file
147   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 disappear
161         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     esac
168 
169     # if server isnt running, then pid-file will never be updated
170     if test -n "$pid"; then
171       if kill -0 "$pid" 2>/dev/null; then
172         :  # the server still runs
173       else
174         # The server may have exited between the last pid-file check and now.  
175         if test -n "$avoid_race_condition"; then
176           avoid_race_condition=""
177           continue  # Check again.
178         fi
179 
180         # theres 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       fi
184     fi
185 
186     echo $echo_n ".$echo_c"
187     i=`expr $i + 1`
188     sleep 1
189 
190   done
191 
192   if test -z "$i" ; then
193     log_success_msg
194     return 0
195   else
196     log_failure_msg
197     return 1
198   fi
199 }
200 
201 # Get arguments from the my.cnf file,
202 # the only group, which is read from now on is [mysqld]
203 if test -x ./bin/my_print_defaults
204 then
205   print_defaults="./bin/my_print_defaults"
206 elif test -x $bindir/my_print_defaults
207 then
208   print_defaults="$bindir/my_print_defaults"
209 elif test -x $bindir/mysql_print_defaults
210 then
211   print_defaults="$bindir/mysql_print_defaults"
212 else
213   # Try to find basedir in /etc/my.cnf
214   conf=/etc/my.cnf
215   print_defaults=
216   if test -r $conf
217   then
218     subpat=^[^=]*basedir[^=]*=\(.*\)$
219     dirs=`sed -e "/$subpat/!d" -e s//\1/ $conf`
220     for d in $dirs
221     do
222       d=`echo $d | sed -e s/[     ]//g`
223       if test -x "$d/bin/my_print_defaults"
224       then
225         print_defaults="$d/bin/my_print_defaults"
226         break
227       fi
228       if test -x "$d/bin/mysql_print_defaults"
229       then
230         print_defaults="$d/bin/mysql_print_defaults"
231         break
232       fi
233     done
234   fi
235 
236   # Hope its in the PATH ... but I doubt it
237   test -z "$print_defaults" && print_defaults="my_print_defaults"
238 fi
239 
240 #
241 # Read defaults file from basedir.   If there is no defaults file there
242 # check if its in the old (depricated) place (datadir) and read it from there
243 #
244 
245 extra_args=""
246 if test -r "$basedir/my.cnf"
247 then
248   extra_args="-e $basedir/my.cnf"
249 else
250   if test -r "$datadir/my.cnf"
251   then
252     extra_args="-e $datadir/my.cnf"
253   fi
254 fi
255 
256 parse_server_arguments `$print_defaults $extra_args mysqld server mysql_server mysql.server`
257 
258 #
259 # Set pid file if not given
260 #
261 if test -z "$mysqld_pid_file_path"
262 then
263   mysqld_pid_file_path=$datadir/`hostname`.pid
264 else
265   case "$mysqld_pid_file_path" in
266     /* ) ;;
267     * )  mysqld_pid_file_path="$datadir/$mysqld_pid_file_path" ;;
268   esac
269 fi
270 
271 case "$mode" in
272   ‘start‘)
273     # Start daemon
274 
275     # Safeguard (relative paths, core dumps..)
276     cd $basedir
277 
278     echo $echo_n "Starting MySQL"
279     if test -x $bindir/mysqld_safe
280     then
281       # Give extra arguments to mysqld with the my.cnf file. This script
282       # 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 / SuSE
287       if test -w "$lockdir"
288       then
289         touch "$lock_file_path"
290       fi
291 
292       exit $return_value
293     else
294       log_failure_msg "Couldn‘t find MySQL server ($bindir/mysqld_safe)"
295     fi
296     ;;
297 
298   ‘stop‘)
299     # Stop daemon. We use a signal here to avoid having to know the
300     # root password.
301 
302     if test -s "$mysqld_pid_file_path"
303     then
304       mysqld_pid=`cat "$mysqld_pid_file_path"`
305 
306       if (kill -0 $mysqld_pid 2>/dev/null)
307       then
308         echo $echo_n "Shutting down MySQL"
309         kill $mysqld_pid
310         # 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       else
313         log_failure_msg "MySQL server process #$mysqld_pid is not running!"
314         rm "$mysqld_pid_file_path"
315       fi
316 
317       # Delete lock for RedHat / SuSE
318       if test -f "$lock_file_path"
319       then
320         rm -f "$lock_file_path"
321       fi
322       exit $return_value
323     else
324       log_failure_msg "MySQL server PID file could not be found!"
325     fi
326     ;;
327 
328   ‘restart‘)
329     # Stop the service and regardless of whether it was
330     # running or not, start it again.
331     if $0 stop  $other_args; then
332       $0 start $other_args
333     else
334       log_failure_msg "Failed to stop running server, so refusing to try to start."
335       exit 1
336     fi
337     ;;
338 
339   ‘reload‘|‘force-reload‘)
340     if test -s "$mysqld_pid_file_path" ; then
341       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     else
345       log_failure_msg "MySQL PID file could not be found!"
346       exit 1
347     fi
348     ;;
349   ‘status‘)
350     # First, check to see if pid file exists
351     if test -s "$mysqld_pid_file_path" ; then 
352       read mysqld_pid < "$mysqld_pid_file_path"
353       if kill -0 $mysqld_pid 2>/dev/null ; then 
354         log_success_msg "MySQL running ($mysqld_pid)"
355         exit 0
356       else
357         log_failure_msg "MySQL is not running, but PID file exists"
358         exit 1
359       fi
360     else
361       # Try to find appropriate mysqld process
362       mysqld_pid=`pidof $libexecdir/mysqld`
363 
364       # test if multiple pids exist
365       pid_count=`echo $mysqld_pid | wc -w`
366       if test $pid_count -gt 1 ; then
367         log_failure_msg "Multiple MySQL running but PID file could not be found ($mysqld_pid)"
368         exit 5
369       elif test -z $mysqld_pid ; then 
370         if test -f "$lock_file_path" ; then 
371           log_failure_msg "MySQL is not running, but lock file ($lock_file_path) exists"
372           exit 2
373         fi 
374         log_failure_msg "MySQL is not running"
375         exit 3
376       else
377         log_failure_msg "MySQL is running but PID file could not be found"
378         exit 4
379       fi
380     fi
381     ;;
382     *)
383       # usage
384       basename=`basename "$0"`
385       echo "Usage: $basename  {start|stop|restart|reload|force-reload|status}  [ MySQL server options ]"
386       exit 1
387     ;;
388 esac
389 
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

 

linux通过tar.gz源码包安装mysql

标签:

原文地址:http://www.cnblogs.com/simpman/p/4192942.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!