以下是Linux下Mysql5.6 二进制安装过程的完整攻略:
1、下载Mysql5.6安装包
在官方网站(https://dev.mysql.com/downloads/mysql/5.6.html )上下载对应的Linux二进制版本,下载后解压至指定目录。
示例1:假设下载的二进制文件名为mysql-5.6.50-linux-glibc2.12-x86_64.tar.gz,下载并解压至/opt/mysql/目录下。
2、准备安装环境
通过以下命令安装必备的依赖包:
yum -y install libaio
3、创建MySQL数据存储目录
在/opt/mysql/目录下创建MySQL数据存储目录,并设置权限:
mkdir -p /opt/mysql/data
chmod -R 755 /opt/mysql/data
4、初始化MySQL
将/data目录的权限赋予MySQL服务,并初始化:
chown -R mysql:mysql /opt/mysql/data
cd /opt/mysql
./scripts/mysql_install_db --user=mysql
5、设置MySQL配置文件
在/opt/mysql/目录下创建my.cnf文件,内容如下:
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /opt/mysql
datadir = /opt/mysql/data
character-set-server=utf8
max_connections=1024
[mysql]
no-auto-rehash
6、启动MySQL服务
使用以下命令启动MySQL服务:
cd /opt/mysql
./bin/mysqld_safe &
7、设置MySQL root用户密码
登录MySQL,并设置root用户密码:
./bin/mysql -u root mysql
update user set password=PASSWORD('your_password') where user='root';
flush privileges;
exit;
8、设置启动MySQL服务脚本
创建/etc/my.cnf文件,内容如下:
[mysqld]
datadir=/opt/mysql/data
socket=/tmp/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/opt/mysql/data/mysqld.log
pid-file=/opt/mysql/data/mysqld.pid
然后,在/etc/init.d/目录下创建mysqld文件,内容如下:
#!/bin/bash
#
# mysqld This shell script takes care of starting and stopping
# the MySQL subsystem (mysqld).
#
# chkconfig: - 64 36
# description: MySQL database server.
# processname: mysqld
# config: /etc/my.cnf
# pidfile: /var/run/mysqld/mysqld.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
prog="mysqld"
datadir="/var/lib/mysql"
logfile="/var/log/mysql.log"
[ -f /etc/mysql/my.cnf ] && conf=/etc/mysql/my.cnf
[ -f /etc/my.cnf ] && conf=/etc/my.cnf
[ -z "$conf" ] && conf="$datadir/my.cnf"
# Get config
# or else...
mysqld_args=`$bindir/mysqld --print-defaults $other_args \
| sed "s/^--//g" \
| tr '\n' ' ' \
| sed 's/ / /g' \
| sed 's/ $//'`
if test -z "$mysqld_args" ; then
# Try to find basedir in /etc/my.cnf
test -z "$basedir" && basedir=`awk '/\[mysqld\]/{flag=1} /basedir/{print $3;flag=0} END{}' $conf`
test -z "$basedir" && basedir=/usr
mysqld_args="--basedir=$basedir --datadir=$datadir --plugin-dir=$basedir/lib64/mysql/plugin $mysqld_args"
fi
start() {
. /etc/sysconfig/network
[ ${NETWORKING} = "no" ] && exit 1
[ -x $bindir/mysqld_safe ] || exit 1
[ -f $conf ] || exit 1
echo -n $"Starting $prog: "
MYSQL_HOME=/usr/bin
MYSQL_OPTS="--basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin $mysqld_args"
export MYSQL_HOME MYSQL_OPTS
daemon $MYSQL_HOME/mysqld $MYSQL_OPTS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/mysqld
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mysqld
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $prog
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/mysqld ]; then
stop
start
fi
;;
reload)
mysqladmin reload
RETVAL=$?
;;
force-reload)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|force-reload}"
exit 1
esac
exit $RETVAL
然后启动MySQL服务:
service mysqld start
到此为止,Mysql5.6在linux下的二进制安装已全部完成。
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:Linux下Mysql5.6 二进制安装过程 - Python技术站