RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
CentOS6.3安装MySQL-5.7.10
MySQL的安装分为三种:
1、RPM包安装;
2、二进制包安装;
3、源码安装。

第一种方式比较简单,直接RPM包安装就OK了,或者通过yum源来安装,但无法自定义安装目录。
而第三种方式比较复杂。
一般项目中使用比较多的是通过二进制包来安装,这种安装方式可以根据企业的不同需求进行相关的自定义配置,比如安装在哪个目录,如何配置等。
MySQL5.7与5.6安装有所改变。
CentOS版本
[mysql@new ~]$ cat /etc/redhat-release
CentOS release 6.3 (Final)
[mysql@new ~]$
把安装文件上传至服务器
[mysql@new ~]$ ls
total 535920
-rw-rw-rw-. 1 mysql mysql 548774698 Jan 12 16:53 mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz
解压安装文件
[mysql@new ~]$ tar -xvf mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz
重命名目录
[mysql@guoqing ~]$ mv mysql-5.7.10-linux-glibc2.5-x86_64 mysql
[mysql@guoqing ~]$ ls
mysql  mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz
[mysql@guoqing ~]$ cd mysql
[mysql@guoqing mysql]$ ls
bin  COPYING  docs  include  INSTALL-BINARY  lib  man  README  share  support-files

新建存放数据的目录data
[mysql@guoqing mysql]$ mkdir data
[mysql@guoqing mysql]$ ll
total 164
drwxr-xr-x.  2 mysql mysql   4096 Nov 30 03:54 bin
-rw-r--r--.  1 mysql mysql  17987 Nov 30 03:16 COPYING
drwxrwxr-x.  2 mysql mysql   4096 Jan 12 23:38 data
drwxr-xr-x.  2 mysql mysql   4096 Nov 30 03:54 docs
drwxr-xr-x.  3 mysql mysql   4096 Nov 30 03:54 include
-rw-r--r--.  1 mysql mysql 108090 Nov 30 03:26 INSTALL-BINARY
drwxr-xr-x.  5 mysql mysql   4096 Nov 30 03:54 lib
drwxr-xr-x.  4 mysql mysql   4096 Nov 30 03:54 man
-rw-r--r--.  1 mysql mysql   2478 Nov 30 03:16 README
drwxr-xr-x. 28 mysql mysql   4096 Nov 30 03:54 share
drwxr-xr-x.  2 mysql mysql   4096 Nov 30 03:54 support-files        

拷贝my.cnf文件
[mysql@guoqing mysql]$ su
Password:

[root@guoqing mysql]# cp support-files/my-default.cnf /etc/
[root@guoqing mysql]# chown mysql.mysql /etc/my.cnf

拷贝MySQL服务文件
[root@guoqing mysql]# cp support-files/mysql.server /etc/init.d/mysql
 
在MySQL服务文件中把/usr/local/指替换成自己安装MySQL目录
这里是替换成的home/mysql
[root@guoqing mysql]# vi /etc/init.d/mysql
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900
# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"
# The following variables are only set for letting mysql.server find things.
# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
  basedir=/home/mysql/mysql
  bindir=/home/mysql/mysql/bin
  if test -z "$datadir"
  then
    datadir=/home/mysql/mysql/data
  fi
  sbindir=/home/mysql/mysql/bin
  libexecdir=/home/mysql/mysql/bin
else
  bindir="$basedir/bin"
  if test -z "$datadir"
  then
    datadir="$basedir/data"
  fi
  sbindir="$basedir/sbin"
  libexecdir="$basedir/libexec"
fi
# datadir_set is used to determine if datadir was set (and so should be
# *not* set inside of the --basedir= handler.)
datadir_set=
#
# Use LSB init script functions for printing messages, if possible
#
lsb_functions="/lib/lsb/init-functions"
if test -f $lsb_functions ; then
  . $lsb_functions
else
"/etc/rc.d/init.d/mysql" 393L, 10981C written
[root@guoqing mysql]# exit
exit
修改my.cnf文件,主要添加basedir、datadir
[mysql@guoqing mysql]$ vi /etc/my.cnf
[mysqld]
basedir=/home/mysql/mysql
datadir=/home/mysql/mysql/data
socket=/home/mysql/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/home/mysql/mysql/data/mysqld.log
pid-file=/home/mysql/mysql/data/mysqld/mysqld.pid
"/etc/my.cnf" 11L, 316C written                                                  

初始化MySQL
MySQL 5.7.6之后版本为 ./bin/mysqld --initialize --user=mysql --basedir=/home/mysql/mysql --datadir=/home/mysql/mysql/data/
[mysql@guoqing mysql]$ ./bin/mysqld --initialize --user=mysql --basedir=/home/mysql/mysql --datadir=/home/mysql/mysql/data/
2016-01-12T16:16:14.765586Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2016-01-12T16:16:14.765847Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2016-01-12T16:16:14.766086Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-01-12T16:16:15.038567Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-01-12T16:16:15.095995Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-01-12T16:16:15.166081Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: cdd34871-b947-11e5-8a45-0800272a2c8e.
2016-01-12T16:16:15.168260Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-01-12T16:16:15.168776Z 1 [Note] A temporary password is generated for root@localhost: qnW8usF=o;=e(root用户密码)
 MySQL 5.7.6之前的版本为bin/mysql_install_db --user=mysql   

创建 SSL/RSA 文件
参见:http://dev.mysql.com/doc/refman/5.7/en/mysql-ssl-rsa-setup.html
[mysql@guoqing mysql]$ bin/mysql_ssl_rsa_setup --datadir=/home/mysql/mysql/data/
Generating a 2048 bit RSA private key
...............................+++
.............................................................................................................................................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
............................................+++
...................................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
...........................................................................................................................................+++
......+++
writing new private key to 'client-key.pem'
-----
添加环境变量:/home/mysql/mysql/bin
[mysql@guoqing ~]$ vi .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/home/mysql/mysql/bin
export PATH
~
".bash_profile" 12L, 198C written                                                                             

使变量生效
[mysql@guoqing ~]$ . .bash_profile

启动MySQL服务
[mysql@new ~]$ service mysql start
Starting MySQL.                                            [  OK  ]

登录
用到上面日志中的密码,注意qnW8usF=o;=e全是密码内容
[mysql@guoqing ~]$ mysql -uroot  -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.10
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
修改密码
mysql> set password=password('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql>

至此,MySQL5.7.10安装完成,整体与5.6安装差别不大,便要注意root密码的长度,初始化方式等。
新闻名称:CentOS6.3安装MySQL-5.7.10
当前地址:http://scyingshan.cn/article/jjijpc.html