环境准备:
CentOS6.5 192.168.30.133
安装包准备:
下载安装包 mysql-5.6.15-linux-glibc2.5-x86_64.tar.gz
具体安装:
[[email protected]_RealServer bin]# useradd mysql [[email protected]_RealServer bin]# cd /home/mysql [[email protected]_RealServer mysql]# tar -zxvf mysql-5.6.15-linux-glibc2.5-x86_64.tar.gz [[email protected]_RealServer mysql]# mv mysql-5.6.15-linux-glibc2.5-x86_64 mysql-5.6.15 [[email protected]_RealServer ~]# mkdir /mysql3306 [[email protected]_RealServer ~]# mkdir -p /mysql3306/data [[email protected]_RealServer ~]# mkdir -p /mysql3306/logs [[email protected]_RealServer ~]# mkdir -p /mysql3306/temp [[email protected]_RealServer ~]# chown -R mysql:mysql /mysql3306 [[email protected]_RealServer mysql]# chown -R mysql:mysql mysql-5.6.15/ su - mysql cd /mysql3306/
vim my.cnf 编辑配置文件
[client] port = 3306 socket = /mysql3306/data/mysql.sock [mysqld] user=msql port=3306 #bind-address=0.0.0.0 socket = /mysql3306/data/mysql.sock.3306 pid-file = /mysql3306/data/mysql.pid basedir = /home/mysql/mysql-5.6.15 datadir = /mysql3306/data server-id=1 log-bin=mysql-bin log-bin-index= mysql-bin.index # LOGGING log_error=/mysql3306/logs/mysql-error.log slow_query_log_file= /mysql3306/logs/mysql-slow.log slow_query_log=1 character-sets-dir = /home/mysql/mysql-5.6.15/share/charsets back_log = 2000 max_connections = 1000 connect-timeout = 60 wait-timeout = 28800 net_buffer_length = 16384 max_allowed_packet = 64M thread_stack = 192K thread_cache_size = 20 thread_concurrency = 128 query_cache_size = 25M query_cache_limit = 2M query_cache_min_res_unit = 2 default-time-zone = system character-set-server = utf8 default-storage-engine = InnoDB tmp_table_size = 51M max_heap_table_size = 51M max_binlog_size = 1G max_relay_log_size = 1G [mysql] disable-auto-rehash default-character-set = utf8
保存my.cnf后 mysql帐号初始化数据库
cd /home/mysql/mysql-5.6.15 ./scripts/mysql_install_db --user=mysql --datadir=/mysql3306/data
可以启动数据库了,注意要加上响应的参数
mysql帐号下执行:
/home/mysql/mysql-5.6.15/bin/mysqld_safe --defaults-file=/mysql3306/my.cnf --user=mysql --basedir=/home/mysql/mysql-5.6.15 --datadir=/mysql3306/data/ --ledir=/home/mysql/mysql-5.6.15/bin/
如果不加最后--ledir参数,需要cd 到/home/mysql/mysql-5.6.15下执行上面的命令
mysql -h127.0.0.1 进入数据库进行相应的权限修改,密码修改等。
附录部分:
下面ctlmysql.sh是 通过修改mysql.server来启动停止,查看mysql是否启动的一个脚本:
#!/bin/sh basedir=/home/mysql/mysql-5.6.15 datadir=/mysql3306/data pidfile=/mysql3306/data/mysql.pid conffile=/mysql3306/my.cnf service_startup_timeout=900 bindir="$basedir/bin" sbindir="$basedir/sbin" libexecdir="$basedir/libexec" log_success_msg() { echo " SUCCESS! [email protected]" } log_failure_msg() { echo " ERROR! [email protected]" } PATH="/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin" export PATH case `echo "testing\c"`,`echo -n testing` in *c*,-n*) echo_n= echo_c= ;; *c*,*) echo_n=-n echo_c= ;; *) echo_n= echo_c=‘\c‘ ;; esac wait_for_pid () { verb="$1" # created | removed pid="$2" # process ID of the program operating on the pid-file pid_file_path="$3" # path to the PID file. i=0 avoid_race_condition="by checking again" while test $i -ne $service_startup_timeout ; do case "$verb" in ‘created‘) # wait for a PID-file to pop into existence. test -s "$pid_file_path" && i=‘‘ && break ;; ‘removed‘) # wait for this PID-file to disappear test ! -s "$pid_file_path" && i=‘‘ && break ;; *) echo "wait_for_pid () usage: wait_for_pid created|removed pid pid_file_path" exit 1 ;; esac # if server isn‘t running, then pid-file will never be updated if test -n "$pid"; then if kill -0 "$pid" 2>/dev/null; then : # the server still runs else # The server may have exited between the last pid-file check and now. if test -n "$avoid_race_condition"; then avoid_race_condition="" continue # Check again. fi # there‘s nothing that will affect the file. log_failure_msg "The server quit without updating PID file ($pid_file_path)." return 1 # not waiting any more. fi fi echo $echo_n ".$echo_c" i=`expr $i + 1` sleep 1 done if test -z "$i" ; then log_success_msg return 0 else log_failure_msg return 1 fi } mode=$1 # start or stop [ $# -ge 1 ] && shift case "$mode" in ‘start‘) echo $echo_n "Starting MySQL" if test -x $bindir/mysqld_safe then $bindir/mysqld_safe --defaults-file=$conffile --datadir=$datadir --pid-file=$pidfile --ledir=$bindir >/dev/null 2>&1 & wait_for_pid created "$!" "$pidfile"; return_value=$? exit $return_value else log_failure_msg "Couldn‘t find MySQL server ($bindir/mysqld_safe)" fi ;; ‘stop‘) if test -s "$pidfile" then mysqld_pid=`cat "$pidfile"` if (kill -0 $mysqld_pid 2>/dev/null) then echo $echo_n "Shutting down MySQL" kill $mysqld_pid # mysqld should remove the pid file when it exits, so wait for it. wait_for_pid removed "$mysqld_pid" "$pidfile"; return_value=$? else log_failure_msg "MySQL server process #$mysqld_pid is not running!" rm "$pidfile" fi else log_failure_msg "MySQL server PID file could not be found!" fi ;; ‘restart‘) # Stop the service and regardless of whether it was # running or not, start it again. if $0 stop; then $0 start else log_failure_msg "Failed to stop running server, so refusing to try to start." exit 1 fi ;; ‘status‘) # First, check to see if pid file exists if test -s "$pidfile" ; then read mysqld_pid < "$pidfile" if kill -0 $mysqld_pid 2>/dev/null ; then log_success_msg "MySQL running ($mysqld_pid)" exit 0 else log_failure_msg "MySQL is not running, but PID file exists" exit 1 fi else # Try to find appropriate mysqld process mysqld_pid=`pidof $libexecdir/mysqld` # test if multiple pids exist pid_count=`echo $mysqld_pid | wc -w` if test $pid_count -gt 1 ; then log_failure_msg "Multiple MySQL running but PID file could not be found ($mysqld_pid)" exit 5 elif test -z $mysqld_pid ; then if test -f "$lock_file_path" ; then log_failure_msg "MySQL is not running, but lock file ($lock_file_path) exists" exit 2 fi log_failure_msg "MySQL is not running" exit 3 else log_failure_msg "MySQL is running but PID file could not be found" exit 4 fi fi ;; *) # usage basename=`basename "$0"` echo "Usage: $basename {start|stop|restart|reload|force-reload|status} [ MySQL server options ]" exit 1 ;; esac exit 0
时间: 2024-12-27 19:31:00