首页 > 代码库 > linux通过tar.gz源码包安装mysql

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

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/mysqlSTOPPING server from pid file /var/run/mysqld/mysqld.pid071112 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 directory071112 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 rootbin/mysqladmin: connect to server at localhost failederror: 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 -pEnter 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 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 from an RPM upgrade action114            # Expected: "--skip-networking --skip-grant-tables"115            # They are not checked here, intentionally, as it is the resposibility116            # of the "spec" file author to give correct arguments only.117 118 case `echo "testing\c"`,`echo -n testing` in119     *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 do126     case "$arg" in127       --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=1137     ;;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=0150   avoid_race_condition="by checking again"151 152   while test $i -ne $service_startup_timeout ; do153 154     case "$verb" in155       created)156         # wait for a PID-file to pop into existence.157         test -s "$pid_file_path" && i=‘‘ && break158         ;;159       removed)160         # wait for this PID-file to disappear161         test ! -s "$pid_file_path" && i=‘‘ && break162         ;;163       *)164         echo "wait_for_pid () usage: wait_for_pid created|removed pid pid_file_path"165         exit 1166         ;;167     esac168 169     # if server isnt running, then pid-file will never be updated170     if test -n "$pid"; then171       if kill -0 "$pid" 2>/dev/null; then172         :  # the server still runs173       else174         # 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         # 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       fi184     fi185 186     echo $echo_n ".$echo_c"187     i=`expr $i + 1`188     sleep 1189 190   done191 192   if test -z "$i" ; then193     log_success_msg194     return 0195   else196     log_failure_msg197     return 1198   fi199 }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_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 else213   # 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     do222       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         break227       fi228       if test -x "$d/bin/mysql_print_defaults"229       then230         print_defaults="$d/bin/mysql_print_defaults"231         break232       fi233     done234   fi235 236   # Hope its in the PATH ... but I doubt it237   test -z "$print_defaults" && print_defaults="my_print_defaults"238 fi239 240 #241 # Read defaults file from basedir.   If there is no defaults file there242 # check if its in the old (depricated) place (datadir) and read it from there243 #244 245 extra_args=""246 if test -r "$basedir/my.cnf"247 then248   extra_args="-e $basedir/my.cnf"249 else250   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 if not given260 #261 if test -z "$mysqld_pid_file_path"262 then263   mysqld_pid_file_path=$datadir/`hostname`.pid264 else265   case "$mysqld_pid_file_path" in266     /* ) ;;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=http://www.mamicode.com/$?>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=http://www.mamicode.com/$?>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" ; 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 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 ; 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 2373         fi 374         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

 

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