设为首页 收藏本站
查看: 415|回复: 0

[经验分享] mysql 的二进制安装

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-5-6 10:07:52 | 显示全部楼层 |阅读模式
二进制安装 其实就是已经编译好的mysql,做了个压缩包,下载下来,解压缩,简单配置之后,就能使用,‘安装’速度快,往往用于mysql的快速部署。

添加 mysql 用户:

1
2
[iyunv@www ~]# groupadd mysql
[iyunv@www ~]# useradd -s /sbin/nologin -g mysql -M mysql



-s /sbin/nologin 表示禁止该用户登入系统,提高安全性

-g mysql 指定mysql 用户属于mysql组
-M 表示不创建用户家目录(这里没必要创建)


检查刚刚创建的mysql用户和组:

1
2
3
4
[iyunv@www ~]# tail -1 /etc/passwd
mysql:x:501:501::/home/mysql:/sbin/nologin
[iyunv@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
http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz
5.5版本的mysql,空密码,可直接登入

1
2
3
4
5
6
7
8
9
10
11
[iyunv@www ~]# wget http://dev.mysql.com/get/Downloa ... -5.5.49-linux2.6-x8
6_64.tar.gz                #  获取mysql软件压缩包
[iyunv@www ~]# tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz        # 解压
[iyunv@www  ~]# mv mysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49
#   移动到指定的安装目录,目录标明了mysql的版本( 二进制安装可以自定义安装目录 )
[iyunv@www  ~]# ln -s /application/mysql-5.5.49/  /application/mysql
#    创建软链接
[iyunv@www ~]# cd /application/mysql
[iyunv@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 的各种配置样例,根据情况选择配置文件。
1
[iyunv@www mysql]# /bin/cp support-files/my-small.cnf /etc/my.cnf





初始化 mysql 数据库文件:
1
2
3
4
5
6
7
8
[iyunv@www mysql]# mkdir -p /application/mysql/data  # 建立mysql数据文件目录
[iyunv@www mysql]# chown -R mysql.mysql /application/mysql/  
  #  授权mysql用户管理mysql的安装目录
[iyunv@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 数据库:
1
2
3
4
5
6
7
8
[iyunv@www mysql]# cp support-files/mysql.server /etc/init.d/mysqld
#  拷贝 mysql启动脚本到mysql 的命令路径
[iyunv@www mysql]# chmod +x /etc/init.d/mysqld     #  添加执行权限
[iyunv@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的路径都需要替换
[iyunv@www mysql]# /etc/init.d/mysqld start
Starting MySQL... SUCCESS!






设置mysql开机自动启动:
1
2
3
4
[iyunv@www mysql]# chkconfig --add mysqld
[iyunv@www mysql]# chkconfig mysqld on
[iyunv@www mysql]# chkconfig --list mysqld
mysqld             0:off    1:off    2:on    3:on    4:on    5:on    6:off






登入mysql数据库:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[iyunv@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命令的全局使用路径

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[iyunv@www mysql]# echo 'export PATH=/application/mysql/bin:$PATH' >> /etc/profile
#  追加 'export PATH=/application/mysql/bin:$PATH'到 /etc/profile
[iyunv@www mysql]# source /etc/profile
#  使追加内容的生效
#  以上用途为定义mysql全局路径,实现在任意路径执行mysql命令
  
[iyunv@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>
...
[iyunv@www ~]# mysql -uroot -p     # 也可这样登入,不需要使用密码





设置 mysql 的 root密码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[iyunv@www mysql]# mysqladmin -u root password 'redhat'
[iyunv@www mysql]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[iyunv@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 安装,二进制安装可以可更改安装路径,但本质上只是把已经编译好的那过来用而已,如果你有什么特殊的需要,并不能满足。如果你有什么特殊的需要则应该使用 源码编译安装。






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-213310-1-1.html 上篇帖子: MySQL修改root密码的多种方法 下篇帖子: mysql_connect()不支持请检查mysql模块是否正确加载 二进制 mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表