转自: https://blog.csdn.net/zmken497300/article/details/51615678

安装环境

  1. CentOS-7-x86_64-DVD-1511.iso
  2. mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz
  3. mysql_install.sh脚本

mysql_install.sh脚本


  1. #!/bin/bash
  2. #输入mysql压缩文件地址
  3. fileName=$1;
  4. if [ -f ${fileName} ]
  5. then
  6. #解压mysql
  7. tar -zxvf ${fileName};
  8. echo 'mysql解压完成,正在删除/usr/local/mysql文件夹';
  9. rm -rf /usr/local/mysql;
  10. echo '删除文件夹完成,正在移动解压后的文件';
  11. mv ${fileName%%.tar.gz} /usr/local/mysql;
  12. cd /usr/local/mysql;
  13. else
  14. echo '请输入正确的文件';
  15. fi
  16. #如果系统缺少Data:Dumper模块需要打开下面命令
  17. #yum -y install autoconf;
  18. echo '移动完成,正在初始化数据库';
  19. #初始化数据库
  20. #scripts/mysql_install_db --user=mysql;
  21. scripts/mysql_install_db --user=mysql --explicit_defaults_for_timestamp;
  22. #创建mysql用户和组
  23. groupadd mysql;
  24. useradd -g mysql mysql;
  25. #修改文件夹的用户和组
  26. chown -R root .;
  27. chown -R mysql data;
  28. chgrp -R mysql .;
  29. echo '初始化数据库完成,正在修改mysql配置文件';
  30. #修改mysql配置文件
  31. sed -i '/mysqld/a\datadir = \/usr\/local\/mysql\/data' my.cnf;
  32. sed -i '/mysqld/a\basedir = \/usr\/local\/mysql' my.cnf;
  33. sed -i '/mysqld/a\character-set-server=utf8' my.cnf;
  34. sed -i '/mysqld/a\port = 3306' my.cnf;
  35. sed -i '/mysqld/i\[client]' my.cnf;
  36. sed -i '/mysqld/i\port = 3306' my.cnf;
  37. sed -i '/mysqld/i\default-character-set=utf8' my.cnf;
  38. sed -i '/mysqld/i\ ' my.cnf;
  39. sed -i '/mysqld/i\[mysql]' my.cnf;
  40. sed -i '/mysqld/i\default-character-set=utf8' my.cnf;
  41. sed -i '/mysqld/i\ ' my.cnf;
  42. echo '修改mysql配置文件完成,正在将mysql加入服务中';
  43. cp -rf support-files/mysql.server /etc/init.d/mysql
  44. echo 'mysql加入服务完成,正在添加开机自启动';
  45. chkconfig mysql on
  46. echo '添加开机自启动成功';
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55

example


  1. //一键安装
  2. sh mysql_install.sh mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz
  3. //执行完后开启mysql服务
  4. service mysql start
  5. //开启服务失败请按最后错误提示排错,排错后选择性继续
  6. //进去mysql安装目录
  7. cd /usr/local/mysql
  8. //修改root密码
  9. ./bin/mysqladmin -u root password "123456"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

错误1:The server quit without updating PID file问题的解决办法

1.可能进程里已经存在mysql进程

解决方法:用命令“ps -ef|grep mysqld”查看是否有mysqld进程,如果有使用“kill -9 进程号”杀死,然后重新启动mysqld!

2.以前安装mysql的配置文件没有删除

解决办法:用命令“find / -name my.cnf*”查看是否有文件,如果有需要全部删除,

3.selinux惹的祸,如果是centos系统,默认会开启selinux

解决方法:关闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器试试。

4.如果未解决,请百度一下吧

错误2:缺少Data:Dumper模块

打开mysql_install.sh脚本中这一行注释 #yum -y install autoconf;

错误3:’Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)’

首先查找mysql.sock文件在哪里

find / -name mysql.sock
  • 1

我的是在/temp/mysql.sock目录下

找到之后输入命令重启mysql服务后搞定

ln -s /temp/mysql.sock /tmp/mysql.sock
  • 1

Linux-shell脚本-mysql一键安装的更多相关文章

  1. [linux] shell脚本编程-xunsearch安装脚本学习

    安装脚本setup.sh #!/bin/sh # FULL fast install/upgrade script # See help message via `--help' # $Id$ # s ...

  2. Linux 64位下一键安装scipy等科学计算环境

    Linux 64位下一键安装scipy等科学计算环境 采用scipy.org的各种方法试过了,安装还是失败.找到了一键式安装包Anaconda,基本python要用到的库都齐了,而且还可以选择安装到其 ...

  3. linux ——shell 脚本

                                                      linux—shell 脚本  精简基础                 2018/10/30 13 ...

  4. LINUX SHELL脚本攻略笔记[速查]

    Linux Shell脚本攻略笔记[速查] 资源 shell script run shell script echo printf 环境变量和变量 pgrep shell数学运算 命令状态 文件描述 ...

  5. Linux shell脚本编程(三)

    Linux shell脚本编程 流程控制: 循环语句:for,while,until while循环: while CONDITION; do 循环体 done 进入条件:当CONDITION为“真” ...

  6. Linux shell脚本编程(二)

    Linux shell脚本编程(二) 练习:求100以内所有偶数之和; 使用至少三种方法实现; 示例1: #!/bin/bash # declare -i sum=0 #声明一个变量求和,初始值为0 ...

  7. Linux shell脚本编程(一)

    Linux shell脚本编程: 守护进程,服务进程:启动?开机时自动启动: 交互式进程:shell应用程序 广义:GUI,CLI GUI: CLI: 词法分析:命令,选项,参数 内建命令: 外部命令 ...

  8. Linux Shell 脚本入门

    linux shell 脚本格式 #!/bin/sh#..... (注释)命令...命令... 使用vi 创建完成之后需设置权限 chmod +x filename.sh 执行命令: ./filena ...

  9. Linux Shell脚本入门--cut命令

    Linux Shell脚本入门--cut命令 cut cut 命令可以从一个文本文件或者文本流中提取文本列. cut语法 [root@www ~]# cut -d'分隔字符' -f fields &l ...

随机推荐

  1. 零基础学python-2.3 凝视

    在python里面,使用"#"号表示凝视的開始,一整行到结束就是凝视,他的主要作用提示这段代码到底有什么用处 print("---------欢迎来到猜数字的地方.请開始 ...

  2. UVA 10917 Walk Through the Forest SPFA

    uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= ...

  3. LA 3135 - Argus

    看题:传送门 大意就是让你编写一个称为argus的系统,这个系统支持一个register的命令: Register  Q_num Period 该命令注册了一个触发器,它每Period秒就会残生一个编 ...

  4. 使用ClassyShark压缩你的项目

    原文链接 : Shrinking Your Build With No Rules and do it with Class(yShark) 原文作者 : Roberto Orgiu 译文出自 : 开 ...

  5. ZOJ List the Books 水~

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1727 题目大意: 给你书名.出版时间.价格,让你按照一定的顺序排序.. 其中题 ...

  6. IOS8刷机之后

    用的4s,明显感觉卡- =BUG也非常多,点击设置都闪退..有些应用打不开. 不建议非开发人员尝试. 眼下发现的bug有:同一时候关闭多个应用会造成应用无法关闭. 常常重新启动.耗电没留意.

  7. 我的前端规范——JavaScript篇

    相关文章 简书原文:https://www.jianshu.com/p/5918c283cdc3 我的前端规范——开篇:http://www.cnblogs.com/shcrk/p/9271561.h ...

  8. 终端中经常使用的shell 命令

    Mac 在shell命令终端中,Ctrl+n相当于方向向下的方向键,Ctrl+p相当于方向向上的方向键. 在命令终端中通过它们或者方向键能够实现对历史命令的高速查找.这也是高速输入命令的技巧. 在命令 ...

  9. 【codeforces 742A】Arpa’s hard exam and Mehrdad’s naive cheat

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  10. Spring ContextLoaderListener与DispatcherServlet所加载的applicationContext的区别

    http://www.lai18.com/content/9755931.html Spring 容器(Spring 的上下文) https://my.oschina.net/jast90/blog/ ...