aa0660 发表于 2018-10-3 10:09:04

1.1 Mysql安装

  mysql是数据库文件(存储数据);
  1.下载(猿课论坛链接或者官网)合适版本(官网5.7,我们学习用5.1);免编译的二进制包。源码包就需要编译器编译成能够支持的二进制文件。注意下载的时候和系统位数(32位/64位)的区分
  # cd/usr/local/src/
   wgethttp://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz
  # ls
  # du -shmysql-5.1.73-linux-x86_64-glibc23.tar.gz
  2.解压tar
  # tar zxvf mysql-5.1.73-linux-x86_64-glibc23.tar.gz
  # ls
  mysql-5.1.73-linux-x86_64-glibc23mysql-5.1.73-linux-x86_64-glibc23.tar.gz
  3、建立mysql用户
  创建运行mysql的账户不需要登陆可不创建家目录
  # useradd -s /sbin/nologin -M mysql
  # ls /home 验证
  aming jishanmysqluser1 user2user4user9
  4.移动并重命名。把解压完的数据移动到/usr/local/mysql
  
  # mv mysql-5.1.73-linux-x86_64-glibc23   /usr/local/mysql 移动带重命名 之前这个目录不存在/usr/local/mysq
  查看mysql文件
  # ls /usr/local/mysql 验证    /usr/local/mysql等于mysql-5.1.73-linux-x86_64-glibc23
  bin   datainclude         lib mysql-testscriptssql-bench
  COPYING docsINSTALL-BINARYman README      share    support-files
  5.初始化数据库
  进入cd/usr/local/mysql
  # cd /usr/local/mysql
  创建存放mysql数据的文件夹并更改权限
  # mkdir -p /data/mysql
  # chown -R mysql /data/mysql
  #./scripts/mysql_install_db --user=mysql--datadir=/data/mysql 初始化完成就有两个“ok”。也可以用命令 echo$? 检测,如果输出为0 表示成功。
  Installing MySQL system tables...
  OK
  Filling help tables...
  OK
备注:如果是版本mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz编译会报错,#因为我的linux是最小化安装的,这里报错缺少共享库文件,没关系,我们安装一下就可以了。 yum install -y libaio  # ./scripts/mysql_install_db--user=mysql--datadir=/dat                                  a/mysql
  Installing MySQL system tables..../bin/mysqld: errorwhile loading shared librar                                  ies:libaio.so.1: cannot open shared object file: No such file or directory
  # ./scripts/mysql_install_db--user=mysql--datadir=/data/mysql
  Installing MySQL system tables..../bin/mysqld: errorwhile loading shared libraries: libaio.so.1: cannot open shared object file: Nosuch file or directory
  #yum install -y libaio   5.5版本安装这个yum install -y libaio*
  6.拷贝配置文件,放在相应的目录里面。
  # cd support-files/ 将配置文件放在相应的目录里面。配置文件存放目录
  # ls
  binary-configure   my-huge.cnf            mysqld_multi.server
  config.huge.ini    my-innodb-heavy-4G.cnfmysql-log-rotate
  config.medium.inimy-large.cnf         mysql.server
  config.small.ini   my-medium.cnf          ndb-config-2-node.ini
  magic            my-small.cnf
  # cp my-large.cnf /etc/my.cnf先将my-large.cnf拷贝到etc/my.cnf下并覆盖之前的配置文件
  cp:是否覆盖"/etc/my.cnf"? y
  备注:如果是版本mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz需要执行cpmy-default.cnf /etc/my.cnf
  # ls
  binary-configure magicmy-default.cnf mysqld_multi.server mysql-log-rotatemysql.server
  # cp my-large.cnf /etc/my.cnf
  cp: 无法获取"my-large.cnf"的文件状态(stat): 没有那个文件或目录
  -bash: syntax error near unexpected token `('
  # cp my-default.cnf/etc/my.cnf
  cp:是否覆盖"/etc/my.cnf"? y
  # vim my-large.cnf
  
  port            = 3306
  socket          = /tmp/mysql.sock
  skip-locking
  key_buffer_size = 256M
  max_allowed_packet = 1M
  table_open_cache = 256
  sort_buffer_size = 1M
  read_buffer_size = 1M
  read_rnd_buffer_size = 4M
  myisam_sort_buffer_size = 64M
  thread_cache_size = 8
  query_cache_size= 16M
  # Try number of CPU's*2 forthread_concurrency
  thread_concurrency = 8
  # Don't listen on a TCP/IP port at all.This can be a security enhancement,
  # if all processes that need to connect tomysqld run on the same host.
  # All interaction with mysqld must be madevia Unix sockets or named pipes.
  # Note that using this option withoutenabling named pipes on Windows
  # (via the "enable-named-pipe"option) will render mysqld useless!
  #
  #skip-networking
  # Replication Master Server (default)
  # binary logging is required forreplication
  #log-bin=mysql-bin主从的时候用到 前面输入#注释
  # binary logging format - mixed recommended
  #binlog_format=mixed

  # required unique>  # defaults to 1 if master-host is not set
  # but will not function as a master ifomitted
  #server-id       = 1
  7.拷贝启动脚本。加入到系统服务列表中并启动服务。
  # cp mysql.server /etc/init.d/mysqld
# chmod 755 /etc/init.d/mysqld电子书上的说明,视频上介绍无  
  8、修改启动脚本
  # vim /etc/init.d/mysqld
  basedir=/usr/local/mysql
  datadir=/data/mysql
  9、把启动脚本加入系统服务项,并设定开机启动,启动mysql
  # chkconfig --add mysqld    加入服务列表
  # chkconfig mysqld on
# /etc/init.d/mysqld startservice mysqld start  Starting MySQL.. SUCCESS!
  # netstat -lnp |grep mysql 验证成功
http://blog.51cto.com/e/u261/themes/default/images/spacer.gif
  tcp       0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      3418/mysqld
  unix 2      [ ACC ]   STREAM    LISTENING   295673418/mysqld         /tmp/mysql.sock
  #
http://blog.51cto.com/e/u261/themes/default/images/spacer.gif
  5.6安装可以参考这个
  http://blog.csdn.net/noob_f/article/details/51399335
  5.7实战安装mysql-5.7.12可以参考这个
  http://ask.apelearn.com/question/13004


页: [1]
查看完整版本: 1.1 Mysql安装