二进制安装 其实就是已经编译好的mysql,做了个压缩包,下载下来,解压缩,简单配置之后,就能使用,‘安装’速度快,往往用于mysql的快速部署。
添加 mysql 用户:
[root@www ~]# groupadd mysql
[root@www ~]# useradd -s /sbin/nologin -g mysql -M mysql
-s /sbin/nologin 表示禁止该用户登入系统,提高安全性
-g mysql 指定mysql 用户属于mysql组
-M 表示不创建用户家目录(这里没必要创建)
检查刚刚创建的mysql用户和组:
[root@www ~]# tail -1 /etc/passwd
mysql:x:501:501::/home/mysql:/sbin/nologin
[root@www ~]# id mysql
uid=501(mysql) gid=501(mysql) groups=501(mysql)
获取mysql软件包:
在mysql官网 选Linux - Generic本文用的包是 mysql-5.5.49-linux2.6-x86_64.tar.gz
平台是 centos6.4
5.5版本的mysql,空密码,可直接登入
[root@www ~]# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49-linux2.6-x8
6_64.tar.gz # 获取mysql软件压缩包
[root@www ~]# tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz # 解压
[root@www ~]# mv mysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49
# 移动到指定的安装目录,目录标明了mysql的版本( 二进制安装可以自定义安装目录 )
[root@www ~]# ln -s /application/mysql-5.5.49/ /application/mysql
# 创建软链接
[root@www ~]# cd /application/mysql
[root@www mysql]# ls
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files
初始化 mysql 配置文件 my.cnf:
在support-file 下有 my.cnf 的各种配置样例,根据情况选择配置文件。[root@www mysql]# /bin/cp support-files/my-small.cnf /etc/my.cnf
初始化 mysql 数据库文件:[root@www mysql]# mkdir -p /application/mysql/data # 建立mysql数据文件目录
[root@www mysql]# chown -R mysql.mysql /application/mysql/
# 授权mysql用户管理mysql的安装目录
[root@www mysql]# /application/mysql/scripts/mysql_install_db \ # 初始化mysql数据库文件
> --basedir=/application/mysql \ # 指定mysql目录
> --datadir=/application/mysql/data \ # 指定mysql数据文件目录
> --user=mysql # 指定用户
# 初始化成功会有2个 OK ,如果有ERROR 错误,就要去解决,再初始化
注意:有些软件包的 mysql_install_db 不在 scripts 目录下 ,可能在 bin目录下或其他目录下
配置并启动 mysql 数据库:[root@www mysql]# cp support-files/mysql.server /etc/init.d/mysqld
# 拷贝 mysql启动脚本到mysql 的命令路径
[root@www mysql]# chmod +x /etc/init.d/mysqld # 添加执行权限
[root@www mysql]# sed -i ‘s#/usr/local/mysql#/application/mysql#g‘
/application/mysql/bin/mysqld_safe /etc/init.d/mysqld
# mysql 二进制默认安装路径是/usr/local/mysql,启动脚本里是/usr/local/mysql的路径都需要替换
[root@www mysql]# /etc/init.d/mysqld start
Starting MySQL... SUCCESS!
设置mysql开机自动启动:[root@www mysql]# chkconfig --add mysqld
[root@www mysql]# chkconfig mysqld on
[root@www mysql]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
登入mysql数据库:[root@www ~]# /application/mysql/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.49 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql>
这样启动太麻烦了,可配置mysql命令的全局使用路径:[root@www mysql]# echo ‘export PATH=/application/mysql/bin:$PATH‘ >> /etc/profile
# 追加 ‘export PATH=/application/mysql/bin:$PATH‘到 /etc/profile
[root@www mysql]# source /etc/profile
# 使追加内容的生效
# 以上用途为定义mysql全局路径,实现在任意路径执行mysql命令
[root@www ~]# mysql # 直接进入mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.49 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql>
...
[root@www ~]# mysql -uroot -p # 也可这样登入,不需要使用密码
设置 mysql 的 root密码:[root@www mysql]# mysqladmin -u root password ‘redhat‘
[root@www mysql]# mysql
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
[root@localhost mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.49 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql>
比起官网的 rpm/yum 安装,二进制安装可以可更改安装路径,但本质上只是把已经编译好的那过来用而已,如果你有什么特殊的需要,并不能满足。如果你有什么特殊的需要则应该使用 源码编译安装。