Home >Database >Mysql Tutorial >mysql binaryVInstall

mysql binaryVInstall

WBOY
WBOYOriginal
2016-06-01 13:12:38791browse

www.cnblogs.com/ruiy

mysql binaryVInstall

下载mysql

1.下载:在http://dev.mysql.com/downloads/mysql/官网上下载mysql-5.5.28-linux2.6-i686.tar.gz.

2.解压

tar -xvf mysql-5.5.28-linux2.6-i686.tar.gz

3.移动到/usr/local/mysql

mv mysql-5.5.28-linux2.6-i686 /usr/local/ln -s mysql-5.5.28-linux2.6-i686/ mysql

4.安装依赖的lib包:执行/usr/local/bin/mysql/bin/mysqld,报错

/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

使用apt-cache search libaio,找到如下软件源

libaio-dev - Linux kernel AIO access library - development fileslibaio1 - Linux kernel AIO access library - shared librarylibaio1-dbg - Linux kernel AIO access library - debugging symbols

使用apt-get install libaio1.

配置用户,目录

shell> groupadd mysqlshell> useradd -r -g mysql mysqlshell> cd /usr/local/mysqlshell> chown -R mysql .shell> chgrp -R mysql .<br>

初始化mysql

shell> scripts/mysql_install_db --user=mysql<br># Next command is optionalshell> cp support-files/my-medium.cnf /etc/my.cnf
# Next command is optionalshell> cp support-files/mysql.server /etc/init.d/mysql.server

 这里最重要的就是初始化mysql的一些权限账户表,默认创建了一个空密码的root用户

启动mysql

最简单的启动方式:

shell> /usr/local/mysql/bin/mysqld --user=mysql<br>

默认情况下使用/usr/local/mysql/data作为mysql的数据目录,包括数据库文件,log日志。

常用的mysql启动参数:

/usr/local/mysql/bin/mysqld--user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data--port=3306 --socket=/tmp/mysql.sock

推荐的启动mysql

/usr/local/mysql/support-files/mysql.server start

一般来说,没什么特别需要的话就是使用上述脚本启动mysql服务器了,这个脚本可以加入到linux的系统服务。

关闭mysql

最简单的方式

killall mysqld

推荐的方式

/usr/local/mysql/support-files/mysql.server stop

使用mysql.server stop关闭mysqld会销毁pid文件,并做容错操作,但是最后也是调用kill命令kill mysql。

关闭mysql,尽量不要用kill -9 mysql_pid或者是killall -9 mysql,否则mysql进程无法做退出处理,就可能会丢失数据,甚至导致表损坏。

浅析mysql.server脚本的启动流程

mysql.server脚本可以看到在以下脚本调用mysqld_safe这个bash

$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &

默认情况下,$bindir/mysqld_safe就是/usr/local/mysql/bin/mysqld_safe这个shell,我的本机的调用参数如下:

/bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/blue-pc.pid

而mysqld_safe也是一个shell,可以看到在这个脚本在初始化N多变量后,调用

eval_log_error "$cmd"

这个shell function最后就是调用

#echo "Running mysqld: [$cmd]" eval "$cmd"

在我本机,这个$cmd就是

/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/blue-pc.err --pid-file=/usr/local/mysql/data/blue-pc.pid

posted on2014-05-30 07:23秦瑞It行程实录阅读(...) 评论(...)编辑收藏

刷新评论刷新页面返回顶部

博客园首页博问新闻闪存程序员招聘知识库

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn