转自: 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. BingMap频繁Add Pushpin和Delete Pushpin会导致内存泄露

    近期在做性能測试的时候发现BingMap内存泄露(memory leak)的问题,查找了一些国外的帖子,发现也有类似的问题,可是没有好的解决的方法. https://social.msdn.micro ...

  2. winform最大化后不遮挡任务栏

    在窗体初始化后添加一句代码 this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea;

  3. 微信支付v2开发(4) 交易通知

    本文介绍如何使用JS API支付时如何获得交易通知. 一.交易通知 用户在成功完成支付后,微信后台通知(POST)商户服务器(notify_url)支付结果.商户可以使用notify_url的通知结果 ...

  4. jquery 获取上一个兄弟元素和下一个兄弟元素

    jQuery.prev(),返回上一个兄弟节点,不是所有的兄弟节点 jQuery.prevAll(),返回所有之前的兄弟节点 jQuery.next(),返回下一个兄弟节点,不是所有的兄弟节点 jQu ...

  5. Codeforces Round #234 (Div. 2):B. Inna and New Matrix of Candies

    B. Inna and New Matrix of Candies time limit per test 1 second memory limit per test 256 megabytes i ...

  6. [Angular] HostListener Method Arguments - Blocking Default Keyboard Behavior

    We are going to see how to using method arguments for @HostListener. First, we can use HostListener ...

  7. [Angular 2] Share Template Content In Another Template With Content Projection <ng-content>

    Angular 1 provided a mechanism to place content from your template inside of another template called ...

  8. 洛谷 P3112 后卫马克Guard Mark

    ->题目链接 题解: 贪心+模拟 #include<algorithm> #include<iostream> #include<cstring> #incl ...

  9. Web系统自动化部署脚本

    Web开发的项目,除了在本地直接运行外,还可能经常需要在服务器上部署. 写了个自动化部署的脚本,仅供参考. 不少地方需要配置路径,个人建议使用绝对路径,不用依赖执行脚本时所在的路径. #!/bin/s ...

  10. [转] Python 爬虫的工具列表 附Github代码下载链接

    转自http://www.36dsj.com/archives/36417 这个列表包含与网页抓取和数据处理的Python库 网络 通用 urllib -网络库(stdlib). requests - ...