mysql 5.7.14 二进制版本详细安装过程

时间:2023-01-26 21:04:25

安装环境:

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise

安装版本

下载链接:http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz

       mysql5.7.7及以上做了很多改变,5.7.7以前安装方法和以前差不多,初始化也保留了mysql_install_db,5.7.7以后则去掉了该脚本,使用了-initialize 或者 --initialize-insecure 参数作为初始化。

      mysql5.7.14版本初始化时候已经抛弃了defaults-file参数文件,所以在初始化时候指定配置文件会出错,同时必须保证datadir为空。

网上很多安装文章都没指定basedir和datadir,以及如何指定自己的配置文件进行多实例安装,本文将是完全个性化安装。

尊重原作,本文地址:http://blog.csdn.net/wlzjsj/article/details/52289482

一、初始化

先看看几个错误的初始化:

1.1 指定参数defaults-file

mysql-5.7.14#bin/mysqld --defaults-file=/data/mysql_root/data/3307/my.cnf --initialize --datadir=/data/mysql_root/data/3307/my.cnf --basedir=/data/mysql_root/mysql-5.7.14 --user=mysql
 2016-08-23T03:16:00.406283Z 0 [Warning] InnoDB: New log files created, LSN=45790 

2016-08-23T03:16:00.406283Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 
2016-08-23T03:16:00.406283Z 0 [ERROR] unknown variable ‘defaults-file=/data/mysql_root/data/3307/my.cnf’ 
2016-08-23T03:16:00.406283Z 0 [ERROR] Aborting

提示未知参数

1.2 去掉该参数指定

/mysql-5.7.14# bin/mysqld --initialize --datadir=/data/mysql_root/data/3308/ --basedir=/data/mysql_root/mysql-5.7.14/ --user=mysql 
2016-08-23T04:21:57.860613Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-08-23T04:21:57.861941Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2016-08-23T04:21:57.861958Z 0 [ERROR] Aborting
提示目录已经存在;

1.3 去掉所有参数指定

mysql-5.7.14# bin/mysqld --initialize-insecure --user=mysql 
mysqld: Can't create directory '/usr/local/mysql/data/' (Errcode: 2 - No such file or directory)
2016-08-23T03:16:00.406283Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-08-23T03:16:00.406382Z 0 [ERROR] Can't find error-message file '/usr/local/mysql/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2016-08-23T03:16:00.407050Z 0 [ERROR] Aborting
错误:提示目录不存在,因为我的mysql目录是在data/mysql_root/mysql5.7.14下。

1.4 指定数据目录和basedir

mysql-5.7.14# bin/mysqld --initialize-insecure--user=mysql --basedir=/data/mysql_root/mysql-5.7.14 --datadir=/data/mysql_root/data/3307/
2016-08-23T03:23:52.819389Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-08-23T03:23:52.931185Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-08-23T03:23:52.951819Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-08-23T03:23:53.005317Z 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: 0446b9e5-68e1-11e6-9405-14187751620e.
2016-08-23T03:23:53.005801Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-08-23T03:23:53.006157Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

    初始化成功了。这里说明下,初始化参数我使用了--initialize-insecure,这样不会设置初始化root密码,如果是 --initialize的话,会随机生成一个密码:

2016-08-23T02:51:45.922520Z 1 [Note] A temporary password is generated for root@localhost: fhbsPu?G0PhU

尊重原作,本文地址:http://blog.csdn.net/wlzjsj/article/details/52289482

我们看下mysqld的帮助:

/mysql-5.7.14# bin/mysqld --verbose --help | more
...
bin/mysqld  Ver 5.7.14 for linux-glibc2.5 on x86_64 (MySQL Community Server (GPL))
Copyright (c) 2000, 2016, 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.


Starts the MySQL database server.


Usage: bin/mysqld [OPTIONS]


Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf 
The following groups are read: mysqld server mysqld-5.7
The following options may be given as the first argument:
--print-defaults        Print the program argument list and exit.
--no-defaults           Don't read default options from any option file,
                        except for login file.
--defaults-file=#       Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
--defaults-group-suffix=#
                        Also read groups with concat(group, suffix)
--login-path=#          Read this path from the login file.
...

二、启动mysql实例

初始化完成后,就开始准备启动,启动还保持着原来的方式,可以使用mysqld_safe启动,所以参数基本差不多。

需要注意的是mysql5.7开始很多参数已经做了调整,配置文件中调整过的参数不能再使用,否则启动会报错。

启动错误:

bin/mysqld_safe --defaults-file=/data1/mysql_root/data/3306/my.cnf --basedir=/data1/mysql_root/mysql-5.6.29 --datadir=/data1/mysql_root/data/3306/ --user=mysql

2016-08-23T03:27:56.348529Z 0 [Note] InnoDB: Buffer pool(s) load completed at 160823 11:27:56
2016-08-23T03:27:56.348614Z 0 [ERROR] unknown variable 'tmp_table_open_size=500M'
2016-08-23T03:27:56.348623Z 0 [ERROR] Aborting

===========================================
2016-08-23T03:19:24.599885Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2016-08-23T03:19:24.600007Z 0 [ERROR] unknown variable 'thread_concurrency=4'
2016-08-23T03:19:24.600014Z 0 [ERROR] Aborting
.....
这里大家可以根据自己启动时候查看错误日志的错误进行调整;

去掉这些错误后,使用

bin/mysqld_safe --defaults-file=/data1/mysql_root/data/3306/my.cnf --basedir=/data1/mysql_root/mysql-5.6.29 --datadir=/data1/mysql_root/data/3306/ --user=mysql &

启动即可。

三、登录

初始化时候使用的--initialize-insecure参数,不会随机生成密码,登录和原来一样。

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

可以看到比原来多了个sys库。

尊重原作,本文地址:http://blog.csdn.net/wlzjsj/article/details/52289482

mysql5.7有做较多的改变和更新,后续有文章再继续写5.7的其它细节。