mysql 5.6.35anzhaung_MySQL-5.6.35详细步骤安装解说

[[email protected] mysql-5.6.35]# chown -R mysql.mysql /application/mysql/

1.2.1.5  检查数据库的链接与授权情况。

[[email protected] ~]# ls /application/mysql-5.6.35/bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-5.6.35/total68drwxr-xr-x 2 mysql mysql 4096 May 12 08:43bin-rw-r--r-- 1 mysql mysql 17987 Nov 28 21:36COPYING

drwxr-xr-x 3 mysql mysql 4096 May 12 08:43data

drwxr-xr-x 2 mysql mysql 4096 May 12 08:42docs

drwxr-xr-x 3 mysql mysql 4096 May 12 08:42include

drwxr-xr-x 3 mysql mysql 4096 May 12 08:43lib

drwxr-xr-x 4 mysql mysql 4096 May 12 08:42man

drwxr-xr-x 10 mysql mysql 4096 May 12 08:43 mysql-test-rw-r--r-- 1 mysql mysql 2496 Nov 28 21:36README

drwxr-xr-x 2 mysql mysql 4096 May 12 08:43scripts

drwxr-xr-x 28 mysql mysql 4096 May 12 08:43share

drwxr-xr-x 4 mysql mysql 4096 May 12 08:44 sql-bench

drwxr-xr-x 2 mysql mysql 4096 May 12 08:43 support-files

1.2.1.6  设置MySQL命令的变量

由于系统默认是不带mysql相关的命令的。我们默认输入mysql进入数据库时会出现如下提示:

#系统报错,没有这个指令

MySQL的相关命令全部位于我们安装目录下的/application/mysql/bin目录下。

[[email protected] mysql]# ll /application/mysql/bin/total504304

-rwxr-xr-x 1 mysql mysql 4903434 May 12 08:35innochecksum-rwxr-xr-x 1 mysql mysql 1560 May 12 08:18msql2mysql-rwxr-xr-x 1 mysql mysql 7677515 May 12 08:33myisamchk-rwxr-xr-x 1 mysql mysql 7208604 May 12 08:33myisam_ftdump-rwxr-xr-x 1 mysql mysql 7031316 May 12 08:33myisamlog-rwxr-xr-x 1 mysql mysql 7308399 May 12 08:33myisampack-rwxr-xr-x 1 mysql mysql 4829467 May 12 08:35my_print_defaults-rwxr-xr-x 1 mysql mysql 9830447 May 12 08:35mysql-rwxr-xr-x 1 mysql mysql 111848 May 12 08:18mysqlaccess-rwxr-xr-x 1 mysql mysql 1702 Nov 28 21:36mysqlaccess.conf-rwxr-xr-x 1 mysql mysql 8768505 May 12 08:35mysqladmin-rwxr-xr-x 1 mysql mysql 9745791 May 12 08:36mysqlbinlog-rwxr-xr-x 1 mysql mysql 10904 May 12 08:18mysqlbug-rwxr-xr-x 1 mysql mysql 8756529 May 12 08:36mysqlcheck-rwxr-xr-x 1 mysql mysql 9980594 May 12 08:36mysql_client_test-rwxr-xr-x 1 mysql mysql 81892029 May 12 08:42mysql_client_test_embedded-rwxr-xr-x 1 mysql mysql 6618 May 12 08:18mysql_config-rwxr-xr-x 1 mysql mysql 8840930 May 12 08:35mysql_config_editor-rwxr-xr-x 1 mysql mysql 4334 May 12 08:18mysql_convert_table_format-rwxr-xr-x 1 mysql mysql 89232825 May 12 08:36mysqld-rwxr-xr-x 1 mysql mysql 26912 May 12 08:18mysqld_multi-rwxr-xr-x 1 mysql mysql 26930 May 12 08:49mysqld_safe-rwxr-xr-x 1 mysql mysql 9022567 May 12 08:36mysqldump-rwxr-xr-x 1 mysql mysql 7424 May 12 08:18mysqldumpslow-rwxr-xr-x 1 mysql mysql 81549155 May 12 08:42mysql_embedded-rwxr-xr-x 1 mysql mysql 3409 May 12 08:18mysql_find_rows-rwxr-xr-x 1 mysql mysql 1366 May 12 08:18mysql_fix_extensions-rwxr-xr-x 1 mysql mysql 34938 May 12 08:18mysqlhotcopy-rwxr-xr-x 1 mysql mysql 8778148 May 12 08:36mysqlimport-rwxr-xr-x 1 mysql mysql 4884710 May 12 08:35mysql_plugin-rwxr-xr-x 1 mysql mysql 10106 May 12 08:18mysql_secure_installation-rwxr-xr-x 1 mysql mysql 17584 May 12 08:18mysql_setpermission-rwxr-xr-x 1 mysql mysql 8748353 May 12 08:36mysqlshow-rwxr-xr-x 1 mysql mysql 8837441 May 12 08:36mysqlslap-rwxr-xr-x 1 mysql mysql 9569147 May 12 08:36mysqltest-rwxr-xr-x 1 mysql mysql 81138435 May 12 08:42mysqltest_embedded-rwxr-xr-x 1 mysql mysql 4460104 May 12 08:36mysql_tzinfo_to_sql-rwxr-xr-x 1 mysql mysql 8921922 May 12 08:35mysql_upgrade-rwxr-xr-x 1 mysql mysql 4826498 May 12 08:35mysql_waitpid-rwxr-xr-x 1 mysql mysql 3976 May 12 08:18mysql_zap-rwxr-xr-x 1 mysql mysql 4939895 May 12 08:35perror-rwxr-xr-x 1 mysql mysql 4613230 May 12 08:35replace-rwxr-xr-x 1 mysql mysql 4828703 May 12 08:35resolveip-rwxr-xr-x 1 mysql mysql 4915350 May 12 08:35 resolve_stack_dump

所以我们要为这个目录下的所有命令加入到系统变量中去,以便我们后期方便使用这些mysql命令。

[[email protected] mysql]# echo ‘export PATH=/application/mysql/bin:$PATH‘ >>/etc/profile

[[email protected] mysql]# ./etc/profile

[[email protected] mysql]# which mysql/application/mysql/bin/mysql

[[email protected] mysql]# echo $PATH/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

为了保证系统变量能够顺利执行MySQL指令,请将/application/mysql/bin目录,设置到系统变量$PATH的最前面。否则可能会在后续使用这些命令的过程中出现问题。

1.2.2 单实例数据库初始化步骤

1.2.2.1  初始化数据库

进入到/application/mysql目录,初始化MyQL配置。

[[email protected] mysql]# cd /application/mysql/

配置说明:

参数

说明

--basedir

数据库安装的目录

--datadir

数据库存放的目录

--user=

使用数据库的用户

当初始化的过程中出现如下信息中有两个“OK”的提示,那么就表示数据库初始化成功!

Installing MySQL system tables...2017-05-12 08:48:12 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation formore details).2017-05-12 08:48:12 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.2017-05-12 08:48:12 0 [Note] /application/mysql/bin/mysqld (mysqld 5.6.35) starting as process 16030...2017-05-12 08:48:12 16030 [Note] InnoDB: Using atomics to refcount buffer pool pages2017-05-12 08:48:12 16030 [Note] InnoDB: The InnoDB memory heap isdisabled2017-05-12 08:48:12 16030[Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2017-05-12 08:48:12 16030 [Note] InnoDB: Memory barrier isnot used2017-05-12 08:48:12 16030 [Note] InnoDB: Compressed tables use zlib 1.2.3

2017-05-12 08:48:12 16030[Note] InnoDB: Using Linux native AIO2017-05-12 08:48:12 16030[Note] InnoDB: Using CPU crc32 instructions2017-05-12 08:48:12 16030 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2017-05-12 08:48:12 16030[Note] InnoDB: Completed initialization of buffer pool2017-05-12 08:48:12 16030 [Note] InnoDB: Highest supported file format isBarracuda.2017-05-12 08:48:12 16030 [Note] InnoDB: 128rollback segment(s) are active.2017-05-12 08:48:12 16030 [Note] InnoDB: Waiting forpurge to start2017-05-12 08:48:12 16030 [Note] InnoDB: 5.6.35 started; log sequence number 1625987

2017-05-12 08:48:12 16030[Note] Binlog end2017-05-12 08:48:12 16030[Note] InnoDB: FTS optimize thread exiting.2017-05-12 08:48:12 16030[Note] InnoDB: Starting shutdown...2017-05-12 08:48:14 16030 [Note] InnoDB: Shutdown completed; log sequence number 1625997OK

Filling help tables...2017-05-12 08:48:14 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation formore details).2017-05-12 08:48:14 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.2017-05-12 08:48:14 0 [Note] /application/mysql/bin/mysqld (mysqld 5.6.35) starting as process 16053...2017-05-12 08:48:14 16053 [Note] InnoDB: Using atomics to refcount buffer pool pages2017-05-12 08:48:14 16053 [Note] InnoDB: The InnoDB memory heap isdisabled2017-05-12 08:48:14 16053[Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2017-05-12 08:48:14 16053 [Note] InnoDB: Memory barrier isnot used2017-05-12 08:48:14 16053 [Note] InnoDB: Compressed tables use zlib 1.2.3

2017-05-12 08:48:14 16053[Note] InnoDB: Using Linux native AIO2017-05-12 08:48:14 16053[Note] InnoDB: Using CPU crc32 instructions2017-05-12 08:48:14 16053 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2017-05-12 08:48:14 16053[Note] InnoDB: Completed initialization of buffer pool2017-05-12 08:48:14 16053 [Note] InnoDB: Highest supported file format isBarracuda.2017-05-12 08:48:14 16053 [Note] InnoDB: 128rollback segment(s) are active.2017-05-12 08:48:14 16053 [Note] InnoDB: Waiting forpurge to start2017-05-12 08:48:14 16053 [Note] InnoDB: 5.6.35 started; log sequence number 1625997

2017-05-12 08:48:14 16053[Note] Binlog end2017-05-12 08:48:14 16053[Note] InnoDB: FTS optimize thread exiting.2017-05-12 08:48:14 16053[Note] InnoDB: Starting shutdown...2017-05-12 08:48:16 16053 [Note] InnoDB: Shutdown completed; log sequence number 1626007OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place foryour system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER!Todoso, start the server, then issue the following commands:/application/mysql/bin/mysqladmin -u root password ‘new-password‘

/application/mysql/bin/mysqladmin -u root -h db02 password ‘new-password‘Alternatively you can run:/application/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created bydefault. This isstrongly recommendedforproduction servers.

See the manualformore instructions.

You can start the MySQL daemon with:

cd . ;/application/mysql/bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.pl

cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQLisavailable on the web at

http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: Found existing config file/application/mysql/my.cnf on the system.

Becausethis file might be inuse, it was not replaced,

but was usedin bootstrap (unless you used --defaults-file)

and when you later start the server.

Thenew default config file was created as /application/mysql/my-new.cnf,

please compare it with your file and take the changes you need.

WARNING: Default config file/etc/my.cnf exists on the system

This file will be read bydefaultby the MySQL server

If youdo not want to use this, either remove it, or use the--defaults-file argument to mysqld_safe when starting the server

1.2.2.2 复制配置文件

从MySQL安装目录的support-files目录中复制一份my-default.cnf到/etc目录下,并改名为my.cnf。这个文件就是数据库启动时首先被调用的配置文件。

[[email protected] mysql]# \cp support-files/my-default.cnf /etc/my.cnf

1.2.2.3  编辑这个配置文件

[[email protected] mysql]# vim /etc/my.cnf

修改与配置绿框中的项目。(默认修改的项目前都有#注释的),取消#的注释。

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

# *** DO NOT EDIT THIS FILE. It‘s a template which will be copied to the

# *** default location during install, and will be replaced ifyou

#***upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # andset to the amount of RAM forthe most important data

# cachein MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size=128M

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

# These are commonlyset, remove the # and set asrequired.

basedir= /application/mysql #数据库安装的目录

datadir= /application/mysql/data #数据库数据存放的目录

port= 3306#数据库的端口

server_id= 1#数据库的ID

socket= /application/mysql/mysql.sock #数据库连接启用的接口文件

log-error = /application/mysql/mysqld.log #数据库的错误日志

# Remove leading # toset options mainly useful forreporting servers.

# The server defaults are fasterfortransactions and fast SELECTs.

# Adjust sizesasneeded, experiment to find the optimal values.

# join_buffer_size=128M

# sort_buffer_size=2M

# read_rnd_buffer_size=2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES~

"/etc/my.cnf" 32L, 1210C 1,1 All

1.2.2.4  替换开机自启动文件中的默认路径

替换MySQL开机自启动中文件默认的目录为自定义的程序的目录。

[[email protected] mysql]# sed -i ‘s#/usr/local/#/application/#g‘ support-files/mysql.server

这个support-files目录下的mysql.server文件,是MySQL数据库用于设置开机自启动服务的文件,我们将它其中默认的路径全部替换为自定义安装数据库的目录。

1.2.2.5  设置MySQL开机自启动

复制刚才修改过后的文件到/etc/init.d/目录,并改名为mysqld

[[email protected] mysql]# \cp support-files/mysql.server /etc/init.d/mysqld

加入到chkconfig开机自启动服务中去。

[[email protected] mysql]# chkconfig --add mysqld

[[email protected] mysql]# chkconfig mysqld on

[[email protected] mysql]# chkconfig--list|grep mysqld

mysqld0:off 1:off 2:on 3:on 4:on 5:on 6:off

1.2.2.6  修改MySQL启动文件

首先还是替换作业,把bin目录下mysqld_safe文件中的所有路径全部改成自定义的程序目录。这个mysqld_safe文件是数据库服务的启动文件,它运行启动时调用的就是我们刚才配置的/etc/my.cnf文件中的参数。

[[email protected] mysql]# sed -i ‘s#/usr/local/#/application/#g‘ bin/mysqld_safe

1.2.2.7  创建数据库的错误日志文件

由于我们在配置文件/etc/my.cnf中,添加设置了log-error = /application/mysql/mysqld.log参数,所以我们需要自己在这个目录下创建一个错误日志文件。这个在MySQL-5.6.35中,必须要被添加的参数,而且只能自己创建添加。并且要授予mysqld.log文件的权限为mysql用户。

[[email protected] mysql]# touch /application/mysql/mysqld.log

[[email protected] mysql]# chown-R mysql.mysql /application/mysql/mysqld.log

如果不做这步操作,那么就会出现如下错误提示:

Starting MySQL.170512 08:49:37 mysqld_safe error: log-error set to ‘/application/mysql/mysqld.log‘, however file don‘t exists. Create writable for user‘mysql‘.

ERROR! The server quit without updating PID file (/application/mysql/data/db02.pid).

1.2.2.8  启动MySQL数据库

我们在编译配置参数-DMYSQL_UNIX_ADDR=/application/mysql-5.6.35/tmp/mysql.sock的时候,这个/tmp目录本身也是不存在的,我们需要通过自己手动的方式在这个目录下自行创建一个/application/mysql-5.6.35/tmp目录,并且不要忘记也要给这个目录授权成mysql账户。

[[email protected] mysql]# mkdir -p /application/mysql-5.6.35/tmp

[[email protected] mysql]# chown-R mysql.mysql /application/mysql-5.6.35/tmp

如果不做这个操作,那么系统在启动MySQL数据库的时候,会提示如下错误信息:

[[email protected] mysql]# /etc/init.d/mysqld start

Starting MySQL.... ERROR! The server quit without updating PID file (/application/mysql/data/db02.pid).

并且当我们查看错误日志中会记录这样的错误提示:

2015-05-12 12:58:22 16699 [ERROR] Can‘t start server : Bind on unix socket: Permission denied

2015-05-12 12:58:22 16699 [ERROR] Do you already have another mysqld server running on socket: /application/mysql-5.6.35/tmp/mysql.sock ?

第一条是告诉你,你所设置的/application/mysql-5.6.35/tmp目录没有mysql账户的权限。

第二条是提示你,你所建立的socket这个文件真的准备好了么?(其实还是在告诉你第一条的问题)。

最后当我们把以上所有的步骤都设置好了之后,就可以正常进入MySQL数据库了!

[[email protected] mysql]# /etc/init.d/mysqld start

Starting MySQL... SUCCESS!3306COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

mysqld16391 mysql 10u IPv6 61275 0t0 TCP *:mysql (LISTEN)

1.2.2.9  登录数据库测试

使用mysql命令登录数据库,如果提示符出现“mysql>”就说明我们顺利的进入了MySQL数据库中了。一般情况下,如果我们在编译配置参数时(也就是1.2.1.3步骤)使用的socket文件路径是/application/mysql-5.6.35/tmp/mysql.sock(编译配置它的参数名是“-DMYSQL_UNIX_ADDR=”) 那么直接在命令行输入mysql就可以登录了。但是我们这里在/etc/my.cnf文件中设置的socket路径是/application/mysql/mysql.sock文件,所以当我们在命令行直接输入mysql指令时,会出现下面的错误提示:

[[email protected] mysql]# mysql

ERROR2002 (HY000): Can‘t connect to local MySQL server through socket‘/application/mysql-5.6.35/tmp/mysql.sock‘(2)

这是因为在mysqld_safe文件启动数据库的时候,它优先调用的是/etc/my.cnf文件中所配置的参数,所以我们在登录数据库时,需要-S参数来指定socket文件进行连接。如果想要直接进入,请将/etc/my.cnf文件中的socket路径设置成我们自己编译安装时候指定的socket文件路径,也就是“/application/mysql-5.6.35/tmp/mysql.sock”即可。当然任何修改了my.cnf文件配置后,请记住一定要重新对数据库进行初始化操作。

[[email protected] mysql]# mysql -S /application/mysql/mysql.sock

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection idis 2Server version:5.6.35Source distribution

Copyright (c)2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracleis 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>

1.2.3 多实例数据库初始化步骤

1.2.3.1  初始化数据库

创建一个目录/data用于存放多个数据库使用。

[[email protected] ~]# mkdir -p /data/3306

1.2.3.2  创建多实例数据库的启动文件与配置文件

创建多实例的启动文件mysql和数据库的配置文件my.cnf。

[[email protected] data]# tree /data/data

└──3306├── my.cnf

└── mysql

参照内容如下:

(1)启动文件mysql的参考内容如下:

[[email protected] 3306]# vim mysql

#!/bin/sh

################################################

#this scripts is created by niwei @2017-05-12#niwei QQ:395294844################################################

#init

port=3306mysql_user="root"mysql_pwd="123456"CmdPath="/application/mysql/bin"mysql_sock="/data/${port}/mysql.sock"#startup function

function_start_mysql()

{if [ ! -e "$mysql_sock"];then

printf"Starting MySQL...\n"

/bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null &

elseprintf"MySQL is running...\n"exit

fi

}

#stop function

function_stop_mysql()

{if [ ! -e "$mysql_sock"];then

printf"MySQL is stopped...\n"exitelseprintf"Stoping MySQL...\n"${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown

fi

}

#restart function

function_restart_mysql()

{

printf"Restarting MySQL...\n"function_stop_mysql

sleep2function_start_mysql

}case $1 instart)

function_start_mysql

;;

stop)

function_stop_mysql

;;

restart)

function_restart_mysql

;;*)

printf"Usage: /data/${port}/mysql {start|stop|restart}\n"esac

(2) 配置文件mysql的参考内容如下:

[[email protected] 3306]# vim my.cnf

[client]

port= 3306socket= /data/3306/mysql.sock

[mysql]

no-auto-rehash

[mysqld]

user=mysql

port= 3306socket= /data/3306/mysql.sock

basedir= /application/mysql

datadir= /data/3306/data

open_files_limit= 1024back_log= 600max_connections= 800max_connect_errors= 3000table_cache= 614external-locking =FALSE

max_allowed_packet=8M

sort_buffer_size=1M

join_buffer_size=1M

thread_cache_size= 100thread_concurrency= 2query_cache_size=2M

query_cache_limit=1M

query_cache_min_res_unit=2k

#default_table_type=InnoDB

thread_stack=192K

#transaction_isolation= READ-COMMITTED

tmp_table_size=2M

max_heap_table_size=2M

long_query_time= 1#log_long_format

#log-error = /data/3306/error.log

#log-slow-queries = /data/3306/slow.log

pid-file = /data/3306/mysql.pid

log-bin = /data/3306/mysql-bin

relay-log = /data/3306/relay-bin

relay-log-info-file = /data/3306/relay-log.info

binlog_cache_size=1M

max_binlog_cache_size=1M

max_binlog_size=2M

expire_logs_days= 7key_buffer_size=16M

read_buffer_size=1M

read_rnd_buffer_size=1M

bulk_insert_buffer_size=1M

#myisam_sort_buffer_size=1M

#myisam_max_sort_file_size=10G

#myisam_max_extra_sort_file_size=10G

#myisam_repair_threads= 1#myisam_recover

lower_case_table_names= 1skip-name-resolve

slave-skip-errors = 1032,1062replicate-ignore-db=mysql

server-id = 1innodb_additional_mem_pool_size=4M

innodb_buffer_pool_size=32M

innodb_data_file_path=ibdata1:128M:autoextend

innodb_file_io_threads= 4innodb_thread_concurrency= 8innodb_flush_log_at_trx_commit= 2innodb_log_buffer_size=2M

innodb_log_file_size=4M

innodb_log_files_in_group= 3innodb_max_dirty_pages_pct= 90innodb_lock_wait_timeout= 120innodb_file_per_table= 0[mysqldump]

quick

max_allowed_packet=2M

[mysqld_safe]

log-error=/data/3306/mysql_niwei3306.err

pid-file=/data/3306/mysqld.pid

如果我们只需要配置并使用多实例的数据库的话,那么my.cnf就不用理会/etc/目录下的my.cnf文件了,因为我们所有的配置文件都使用的是我们自定义目录下的数据库实例配置文件。

1.2.3.3  对MySQL启动脚本文件进行授权作业

[[email protected] mysql]# cd /data/33063306]# find /data -type f -name "mysql"|xargs chmod +3306]# find /data -type f -name "mysql"|xargs ls -l-rwxr-xr-x 1 root root 1180 May 12 13:37 /data/3306/mysql

1.2.3.4  授权mysql用户管理MySQL

[[email protected] 3306]# chown -R mysql.mysql /data/3306]# ll /data

total4drwxr-xr-x 2 mysql mysql 4096 May 12 13:58 3306

1.2.3.5  对多实例数据库进行初始化作业

这里注意一点,很多人容易忘记,笔者一开始也是被坑的很惨。初始化数据库时一定要在数据库安装目录下操作。并且如果要初始化多实例数据库,那么“--datadir=”配置参数的后面要接我们自定义的数据库存放路径。我们这里是自定义在/data/3306/data目录下安装的。这一点请特别注意一下。

[[email protected] 3306]# cd /application/mysql/scripts/3306/data --user=mysql

与单实例初始化数据库相似,当看到初始化数据库过程中出现如下信息绿框中的两个“OK”就代表初始化数据库成功!

Installing MySQL system tables...2017-05-12 14:04:29 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation formore details).2017-05-12 14:04:29 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.2017-05-12 14:04:29 0 [Note] /application/mysql/bin/mysqld (mysqld 5.6.35) starting as process 16067...2017-05-12 14:04:29 16067 [Note] InnoDB: Using atomics to refcount buffer pool pages2017-05-12 14:04:29 16067 [Note] InnoDB: The InnoDB memory heap isdisabled2017-05-12 14:04:29 16067[Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2017-05-12 14:04:29 16067 [Note] InnoDB: Memory barrier isnot used2017-05-12 14:04:29 16067 [Note] InnoDB: Compressed tables use zlib 1.2.3

2017-05-12 14:04:29 16067[Note] InnoDB: Using Linux native AIO2017-05-12 14:04:29 16067[Note] InnoDB: Using CPU crc32 instructions2017-05-12 14:04:29 16067 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2017-05-12 14:04:29 16067[Note] InnoDB: Completed initialization of buffer pool2017-05-12 14:04:29 16067 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!

2017-05-12 14:04:29 16067 [Note] InnoDB: Setting file ./ibdata1 size to 12MB2017-05-12 14:04:29 16067[Note] InnoDB: Database physically writes the file full: wait...2017-05-12 14:04:29 16067 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48MB2017-05-12 14:04:30 16067 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48MB2017-05-12 14:04:31 16067 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile02017-05-12 14:04:31 16067 [Warning] InnoDB: New log files created, LSN=45781

2017-05-12 14:04:31 16067 [Note] InnoDB: Doublewrite buffer not found: creating new

2017-05-12 14:04:31 16067[Note] InnoDB: Doublewrite buffer created2017-05-12 14:04:31 16067 [Note] InnoDB: 128rollback segment(s) are active.2017-05-12 14:04:31 16067[Warning] InnoDB: Creating foreign key constraint system tables.2017-05-12 14:04:31 16067[Note] InnoDB: Foreign key constraint system tables created2017-05-12 14:04:31 16067[Note] InnoDB: Creating tablespace and datafile system tables.2017-05-12 14:04:31 16067[Note] InnoDB: Tablespace and datafile system tables created.2017-05-12 14:04:31 16067 [Note] InnoDB: Waiting forpurge to start2017-05-12 14:04:31 16067 [Note] InnoDB: 5.6.35 started; log sequence number 0

2017-05-12 14:04:32 16067[Note] Binlog end2017-05-12 14:04:32 16067[Note] InnoDB: FTS optimize thread exiting.2017-05-12 14:04:32 16067[Note] InnoDB: Starting shutdown...2017-05-12 14:04:33 16067 [Note] InnoDB: Shutdown completed; log sequence number 1625977OK

Filling help tables...2017-05-12 14:04:33 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation formore details).2017-05-12 14:04:33 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.2017-05-12 14:04:33 0 [Note] /application/mysql/bin/mysqld (mysqld 5.6.35) starting as process 16089...2017-05-12 14:04:33 16089 [Note] InnoDB: Using atomics to refcount buffer pool pages2017-05-12 14:04:33 16089 [Note] InnoDB: The InnoDB memory heap isdisabled2017-05-12 14:04:33 16089[Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2017-05-12 14:04:33 16089 [Note] InnoDB: Memory barrier isnot used2017-05-12 14:04:33 16089 [Note] InnoDB: Compressed tables use zlib 1.2.3

2017-05-12 14:04:33 16089[Note] InnoDB: Using Linux native AIO2017-05-12 14:04:33 16089[Note] InnoDB: Using CPU crc32 instructions2017-05-12 14:04:33 16089 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2017-05-12 14:04:33 16089[Note] InnoDB: Completed initialization of buffer pool2017-05-12 14:04:33 16089 [Note] InnoDB: Highest supported file format isBarracuda.2017-05-12 14:04:33 16089 [Note] InnoDB: 128rollback segment(s) are active.2017-05-12 14:04:33 16089 [Note] InnoDB: Waiting forpurge to start2017-05-12 14:04:33 16089 [Note] InnoDB: 5.6.35 started; log sequence number 1625977

2017-05-12 14:04:33 16089[Note] Binlog end2017-05-12 14:04:33 16089[Note] InnoDB: FTS optimize thread exiting.2017-05-12 14:04:33 16089[Note] InnoDB: Starting shutdown...2017-05-12 14:04:35 16089 [Note] InnoDB: Shutdown completed; log sequence number 1625987OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place foryour system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER!Todoso, start the server, then issue the following commands:/application/mysql/bin/mysqladmin -u root password ‘new-password‘

/application/mysql/bin/mysqladmin -u root -h db02 password ‘new-password‘Alternatively you can run:/application/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created bydefault. This isstrongly recommendedforproduction servers.

See the manualformore instructions.

You can start the MySQL daemon with:

cd . ;/application/mysql/bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.pl

cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQLisavailable on the web at

http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

Newdefault config file was created as /application/mysql/my.cnf and

will be used bydefaultby the server when you start it.

You may editthisfile to change server settings

WARNING: Default config file/etc/my.cnf exists on the system

This file will be read bydefaultby the MySQL server

If youdo not want to use this, either remove it, or use the--defaults-file argument to mysqld_safe when starting the server

1.2.3.6  修改配置文件my.cnf中的参数

在MySQL-5.6.35中一些配置参数需要进行必要的修改。否则会出现各种各样无法启动数据库服务的问题。有些配置参数与以往低版本的MySQL5.5系列有所不同。

修改“innodb_data_file_path = ibdata1:1024M:autoextend”参数,“ibdata1:”后面的数值不能低于768M,这里为了能够让数据库正常运行,所以我们大小设置成1024M。如果设置参数小于768M的话,那么会在MySQL错误日志中出现如下提示:

2017-05-12 14:20:16 18216 [ERROR] InnoDB: auto-extending data file ./ibdata1 is of a different size 768 pages (rounded down to MB) than specified in the .cnf file: initial 8192 pages, max 0 (relevant if non-zero) pages!

所以我们要把这个参数值设置的稍微大点。

1.2.3.7  删除ib开头的文件

删除/data/3306/data目录中ib开头的三个文件,如果不删除的话,那么在第一次启动数据库时,上面的错误必定会出现。所以如果后续在错误日志中,出现上面的错误提示时,那么请删除/data/3306/data目录下所有ib开头相关的文件(绿框中的文件)。平时我们工作中为了保险起见,可以用mv的方式,把这些不用的文件放置到其他目录下做备份处理。

[[email protected] data]# cd /data/3306/data

[[email protected] data]# ll

total110604

-rw-rw---- 1 mysql mysql 12582912 May 12 14:17ibdata1-rw-rw---- 1 mysql mysql 50331648 May 12 14:17ib_logfile0-rw-rw---- 1 mysql mysql 50331648 May 12 14:17ib_logfile1

drwx------ 2 mysql mysql 4096 May 12 14:17mysql

drwx------ 2 mysql mysql 4096 May 12 14:17performance_schema

drwx------ 2 mysql mysql 4096 May 12 14:17 test

1.2.3.8  注释my.cnf配置文件中的参数

修改/data/3306/my.cnf配置文件中的参数“table_cache = 614”前进行注释处理。如果不将这条记录注释,那么在MySQL错误日志中会出现如下提示:

2017-05-12 14:32:05 21154 [ERROR] /application/mysql-5.6.35/bin/mysqld: unknown variable ‘table_cache=614‘

1.2.3.9  创建错误日志

创建一个错误日志,并授权成mysql账户。

[[email protected] scripts]# touch /data/3306/mysql_niwei3306.err

[[email protected] scripts]# chown-R mysql.mysql /data

[[email protected] scripts]# ll/data/3306/mysql_niwei3306.err-rw-r--r-- 1 mysql mysql 0 May 12 14:19 /data/3306/mysql_niwei3306.err

如果不创建这个文件而直接启动数据库的话,就会出现如下提示的报错!

[[email protected] scripts]# /data/3306/mysql start

Starting MySQL...

[[email protected] scripts]#170512 14:17:58 mysqld_safe error: log-error set to ‘/data/3306/mysql_niwei3306.err‘, however file don‘t exists. Create writable for user‘mysql‘.

1.2.3.10  启动数据库服务

启动数据库服务并检查是否有问题。

[[email protected] 3306]# /data/3306/mysql start

Starting MySQL...

[[email protected]3306]# lsof -i:3306COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

mysqld21885 mysql 12u IPv6 65362 0t0 TCP *:mysql (LISTEN)

1.2.3.11  登录数据库测试

与单实例数据库相似,由于我们配置的是多实例数据库,所以每次登录这些多实例数据库时,我们都必须要指定socket文件来登录,如果未来有多个多实例数据库的话,都需要指定每一个对应该实例数据库的socket文件来登录。

[[email protected] 3306]# mysql -S /data/3306/mysql.sock

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection idis 1Server version:5.6.35-log Source distribution

Copyright (c)2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracleis 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>

如果你看了本文档,在安装过程中还出现问题的话,请活用日志文件来进行排错处理!

你可能感兴趣的:(mysql,5.6.35anzhaung)