比尔云BierYun--阿里云最新优惠活动
阿里云优惠码丨阿里云代金券

【MySQL学习笔记】CentOS6.6上二进制方式安装MySQL5.6

【MySQL学习笔记】CentOS6.6上二进制方式安装MySQL5.6http://www.bieryun.com/1080.html

二进制安装时基于已安装好的MySQL

可以参考这个: 【MySQL学习笔记】CentOS 6.6上源码编译方式安装MySQL 5.6

把已安装好的mysql,也就是把/usr/local/mysql 目录直接打包压缩,把压缩文件放到要安装MySQL的机器上,解压之后,MySQL就安装好了。

不过,安装好之后,好需要进行各种配置

安装、配置过程如下:

一、把mysql程序打包 压缩

复制代码
  1. [root@wc1 mysql]# cd /usr/local/mysql
  2. [root@wc1 mysql]# tar -zcvf /root/Desktop/mysql-5.6.12.bin.tar.gz

二、把压缩包复制到要安装mysql的机器上解压,然后移动到目标目录

复制代码
  1. [root@wc1 mysql]# cd /root/Desktop
  2. [root@wc1 Desktop]# tar -zxvf /root/Desktop/mysql-5.6.12.bin.tar.gz
  3. [root@wc1 Desktop]# mv usr/local/mysql  /usr/local

三:在shell脚本中执行su命令、转换文件格式

由于脚本文件在运行的过程中要切换到mysql用户,也就是命令:su – mysql,导致接下去的命令行都不执行,只有在输入 exit 命令后,才会继续运行,但是运行之后也是有问题的。

然后,搜索解决的办法,从这篇文章中受到启发:http://blog.csdn.net/huashnag/article/details/43967237,感谢作者。

另外,由于shell脚本是在windows下编辑的,linux环境中无法运行,报错:

command not found 3:

command not found 4

command not found 5

QQ群中一个热心的网友说,这是格式问题,需要安装dos2unix,把windows下编辑的文件,转成unix格式的,类似这样:

dos2unix 文件名

然后,在网上搜索安装方法,安装dos2unix:

复制代码
  1. [root@wc1 Desktop]# yum -y dos2unix unix2dos
  2. Loaded plugins: fastestmirror, refresh-packagekit, security
  3. No such command: dos2unix. Please use /usr/bin/yum –help
  4. [root@wc1 Desktop]# yum -y install dos2unix unix2dos
  5. Loaded plugins: fastestmirror, refresh-packagekit, security
  6. Setting up Install Process
  7. Loading mirror speeds from cached hostfile
  8. * base: centos.ustc.edu.cn
  9. * extras: mirrors.163.com
  10. * updates: mirrors.163.com
  11. Resolving Dependencies
  12. –> Running transaction check
  13. —> Package dos2unix.x86_64 0:3.1-37.el6 will be installed
  14. —> Package unix2dos.x86_64 0:2.2-35.el6 will be installed
  15. –> Finished Dependency Resolution
  16. Dependencies Resolved
  17. ================================================================================
  18. Package            Arch             Version               Repository      Size
  19. ================================================================================
  20. Installing:
  21. dos2unix           x86_64           3.1-37.el6            base            16 k
  22. unix2dos           x86_64           2.2-35.el6            base            14 k
  23. Transaction Summary
  24. ================================================================================
  25. Install       2 Package(s)
  26. Total download size: 30 k
  27. Installed size: 35 k
  28. Downloading Packages:
  29. (1/2): dos2unix-3.1-37.el6.x86_64.rpm                    |  16 kB     00:00
  30. (2/2): unix2dos-2.2-35.el6.x86_64.rpm                    |  14 kB     00:00
  31. ——————————————————————————–
  32. Total                                            76 kB/s |  30 kB     00:00
  33. warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
  34. Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
  35. Importing GPG key 0xC105B9DE:
  36. Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>
  37. Package: centos-release-6-6.el6.centos.12.2.x86_64 (@anaconda-CentOS-201410241409.x86_64/6.6)
  38. From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
  39. Running rpm_check_debug
  40. Running Transaction Test
  41. Transaction Test Succeeded
  42. Running Transaction
  43.   Installing : unix2dos-2.2-35.el6.x86_64                                                      1/2
  44.   Installing : dos2unix-3.1-37.el6.x86_64                                                      2/2
  45.   Verifying  : dos2unix-3.1-37.el6.x86_64                                                      1/2
  46.   Verifying  : unix2dos-2.2-35.el6.x86_64                                                      2/2
  47. Installed:
  48.   dos2unix.x86_64 0:3.1-37.el6                     unix2dos.x86_64 0:2.2-35.el6
  49. Complete!
  50. [root@wc1 Desktop]# </centos-6-key@centos.org>

四、脚本

主要有2个脚本文件。

1、mysql_run.sh:在root账号下运行,主要是做一些预备的工作,最后会调用mysql.sh脚本。

2、mysql.sh:在mysql账号下运行。

五、mysql_run.sh

复制代码
  1. #1.创建用户组、用户、修改目录属主
  2. groupadd mysql
  3. useradd -g mysql mysql
  4. chown -R mysql:mysql /usr/local/mysql
  5. #2.修改用户的bash配置文件,在用户登录后,设置语言、执行路径 环境变量
  6. echo “export LANG=zh_CN.UTF-8” >> /home/mysql/.bash_profile
  7. echo “export PATH=/usr/local/mysql/bin:\$PATH” >> /home/mysql/.bash_profile
  8. #3.创建mysql要用的数据目录
  9. mkdir -p /data/mysqldata/{3306/{data,tmp,binlog},backup,scripts}
  10. chown -R mysql:mysql /data/mysqldata
  11. #4.设置开机自启动项,里面引用到的脚本是在mysql.sh脚本中创建的
复制代码
  1. #  通过sed编辑/etc/sudoers文件,使得mysql账号能使用sudo命令、在在终端tty也能执行sudo命令
  2. echo “”>>  /etc/rc.local
  3. echo “#autostart mysql”>> vi /etc/rc.local
  4. echo “sudo -i -u mysql /data/mysqldata/scripts/mysql_db_startup.sh 3306 > /home/mysql/mysql_db_startup.log 2>&1” >> /etc/rc.local
  5. sed -i -e ‘/^root\s*ALL=(ALL)\s*ALL$/a\mysql    ALL=(ALL)    ALL’ -e’s/^Defaults    requiretty/#Defaults    requiretty/’  /etc/sudoers
  6. #5.在/etc/security/limits.conf文件中增加nproc最大能打开的进程数、nofile最大能打开的文件数 限制
  7. echo “mysql    soft    nproc           2047” >>/etc/security/limits.conf
  8. echo “mysql    hard    nproc           16384” >>/etc/security/limits.conf
  9. echo “mysql    soft    nofile           1024” >>/etc/security/limits.conf
  10. echo “mysql    hard    nofile           65536” >>/etc/security/limits.conf
  11. #6.把mysql.sh文件拷贝到mysql账户的home目录下,设置执行权限
  12. cp mysql.sh /home/mysql/mysql.sh
  13. chmod 777 /home/mysql/mysql.sh
  14. su – mysql -c ./mysql.sh

六:mysql.sh

复制代码
  1. #7.安装mysl数据库
  2. cd /usr/local/mysql/scripts
  3. ./mysql_install_db –datadir=/data/mysqldata/3306/data –basedir=/usr/local/mysql
  4. #8.创建my.cnf文件,并输入内容
  5. touch /data/mysqldata/3306/my.cnf
  6. cat >>/data/mysqldata/3306/my.cnf <<eof basedir=”/usr/local/mysql” binlog_cache_size=”32M” binlog_format=”mixed” buffer=”” datadir=”/data/mysqldata/3306/data” expire-logs_days=”14″ explicit_defaults_for_timestamp=”” innodb=”” innodb_buffer_pool_size=”300M” innodb_data_file_path=”ibdata1:10M:autoextend” innodb_log_file_size=”256M” innodb_log_files_in_group=”3″ join_buffer_size=”2M” log=”” log-bin=”/data/mysqldata/3306/binlog/mysql-bin” log_error=”../mysql-error.log” log_output=”FILE” max_allowed_packet=”256M” max_binlog_cache_size=”512M” max_binlog_size=”512M” max_heap_table_size=”16M” mysql=”” net_buffer_length=”8K” no-auto_rehash=”” open_files_limit=”10240″ pid-file=”/data/mysqldata/3306/mysql.pid” port=”3306″ prompt=”(\u@\h)” read_buffer_size=”1M” read_rnd_buffer_size=”8M” server=”” slow_query_log=”1″ slow_query_log_file=”../slow_query.log” socket=”/data/mysqldata/3306/mysql.sock” sort_buffer_size=”1M” sql_mode=”NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES” the=”” tmpdir=”/data/mysqldata/3306/tmp” user=”mysql”>\_
  7. default-character-set = gbk
  8. EOF
  9. #9.创建mysql服务管理脚本,共4个文件
  10. touch /data/mysqldata/scripts/mysql_env.ini
  11. cat >>/data/mysqldata/scripts/mysql_env.ini <<eof -ne=”” 1=”” cat=”” check=”” data=”” else=”” env=”” eof=”” fi=”” host_port=”3306″ if=”” mysql_db_startup.sh=”” mysql_pass=””” mysql_user=””” mysqldata=”” parameter=”” scripts=”” set=”” then=”” touch=””>>/data/mysqldata/scripts/mysql_db_startup.sh <<eof –defaults-file=”/data/mysqldata/\${HOST_PORT}/my.cnf” bin=”” cat=”” data=”” echo=”” eof=”” local=”” mysql=”” mysql_db_shutdown.sh=”” mysql_env.ini=”” mysqld_safe=”” mysqldata=”” scripts=”” service:=”” sh=”” source=”” startup=”” touch=”” usr=””>>/data/mysqldata/scripts/mysql_db_shutdown.sh <<eof -s=”” bin=”” cat=”” data=”” echo=”” eof=”” local=”” mysql=”” mysql.sock=”” mysql_env.ini=”” mysqladmin=”” mysqldata=”” mysqlplus.sh=”” scripts=”” service:=”” sh=”” shutdown=”” source=”” touch=”” usr=””>>/data/mysqldata/scripts/mysqlplus.sh <<eof -s=”” .sh=”” 2=”” 700=”” bin=”” chmod=”” data=”” echo=”” eof=”” export=”” local=”” login=”” mysql=”” mysql.sock=”” mysql_env.ini=”” mysqldata=”” path=”/data/mysqldata/scripts:\$PATH”” scripts=”” service:=”” sh=”” source=”” usr=”” x=””>> /home/mysql/.bash_profile
  12. source ~/.bash_profile</eof></eof></eof></eof></eof>
未经允许不得转载:比尔云 » 【MySQL学习笔记】CentOS6.6上二进制方式安装MySQL5.6
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

强烈推荐

高性能SSD云服务器ECS抗攻击,高可用云数据库RDS