转自: 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. [RxJS] How To get the results of two HTTP requests made in sequence

    switchMap can chain two HTTP requests together, creating one request based on the results of the fir ...

  2. 机房收费 & 廊院食堂

    做机房收费系统时.常常想这个一般用户指的是谁?我当初以为是学生......可能是被数据库中的student带跑偏了...... 事实上把我们的系统联系一下实际,就会非常easy想到一般用户指的是谁的位 ...

  3. Eclipse手动配置svn

    1.在Eclipse根目录下建一个任意文件夹(如plugin),在该文件夹下建一个以该插件名命名的文件夹(如SVN).2.将下载下的插件文件解压,plugins和features文件夹复制到该文件夹下 ...

  4. Win10系统如何设置所有程序默认以管理员身份运行?

    原文:Win10系统如何设置所有程序默认以管理员身份运行? 在win10系统中有些用户发现一些程序只有使用管理员身份运行能才打开,这样的话就感觉会麻烦很多,那么有没有办法设置所有程序都默认以管理员身份 ...

  5. 介绍array_multisort方法

    介绍array_multisort方法 array_multisort — 对多个数组或多维数组进行排序.其php 手册中的说明如下:  代码如下: bool array_multisort ( ar ...

  6. 关于浏览器不能执行JavaScrip问题的反思

    今天在一篇博客(http://blog.csdn.net/u011043843/article/details/27959563)的时候,写着用于演示的Javascript代码不能再浏览器执行,非常是 ...

  7. linux跟踪线程的方法:LWP和strace命令

    摘要:在使用多线程程序时,有时会遇到程序功能异常的情况,而这种异常情况并不是每次都发生,很难模拟出来.这时就需要运用在程序运行时跟踪线程的手段,而linux系统的LWP和strace命令正是这种技术手 ...

  8. 洛谷 P3112 后卫马克Guard Mark

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

  9. [SCSS] Write Custom Functions with the SCSS @function Directive

    Writing SCSS @functions is similar to writing functions in other programming languages; they can acc ...

  10. ASP.NET 的 ViewState Cookie Session 等的比較

    类型 值保存在哪 值的有效范围 备注 View State client 不能跨页面传递.仅仅能在当前页面保存数据. 在HTML中能够看到ViewState值,只是是加密. 不是明文. ViewSta ...