linux安装mysql5.6.34_linux下安装mysql二进制版本(5.6.34)

版本:社区版 5.6.34

我这里下载的是mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz

1.创建mysql用户和用户组

#groupadd mysql

#useradd -g mysql mysql

#passwd mysql

2.下载解压二进制文件,解压,进入解压出来的文件

[root@host01 db]# tar -xvf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz

[root@host01 db]# mv mysql-5.6.34-linux-glibc2.5-x86_64 mysqlmha

3.在mysqlmha目录下创建如下文件夹

[mysql@host01 mysqlmha]$ cd /db/mysqlmha

[mysql@host01 mysqlmha]$ mkdir conf                        ## 配置文件目录

[mysql@host01 mysqlmha]$ mkdir data                         ##数据文件

[mysql@host01 mysqlmha]$ mkdir redolog                    ##redo日志文件

[mysql@host01 mysqlmha]$ mkdir ibdata                      ##ibdata文件

[mysql@host01 mysqlmha]$ mkdir -p mysqllog/relaylog  ##主从环境relaylog

[mysql@host01 mysqlmha]$ mkdir -p mysqllog/logfile    ##错误日志文件

[mysql@host01 mysqlmha]$ mkdir -p mysqllog/binlog    ##binlog文件

4.创建配置文件

在conf目录下创建配置文件my.cnf,配置文件内容附后.

5.更改文件夹mysqlmha的文件所属用户

[root@host01 db]# chown -R mysql:mysql mysqlmha

6.安装数据库

[root@host01 db]#cd /db/mysqlmha/scripts

[root@host01 db]#./mysql_install_db --user=mysql --basedir=/db/mysqlmha --datadir=/db/mysqlmha/data

执行该步骤的时候有可能遇到如下错误:

错误1:

FATAL ERROR: please install the following Perl modules before executing ./mysql_install_db:

Data::Dumper

解决方法:安装autoconf库

命令:yum -y install autoconf

错误2:

-bash: ./mysql_install_db: /usr/bin/perl: bad interpreter: No such file or directory

貌似提示注释器错误,没有/usr/bin/perl文件或者档案,解决办法(安装perl跟perl-devel即可):

执行:yum -y install perl perl-devel

错误3:

[root@localhost scripts]# ./mysql_install_db --user=mysql --basedir=/opt/mysql5640 --datadir=/opt/mysql5640/data

Installing MySQL system tables.../opt/mysql5640/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

解决办法

[root@example.com data]# yum install -y libaio

错误4:

Installing MySQL system tables.../opt/mysql5640/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

解决办法:

yum -y install numactl

7.创建软连接

[root@host01 db]# mkdir -p /usr/local/mysql/bin

[root@host01 db]# ln -s /db/mysqlmha/bin/mysqld /usr/local/mysql/bin/mysqld

[root@host01 db]# chown -R mysql:mysql /usr/local/mysql

8.启动数据库

[root@host01 db]#./mysqld_safe --defaults-file=/db/mysqlmha/conf/my.cnf --user=mysql

9.登陆数据库修改密码

数据库安装后root账号的初始化密码为空,不需要密码即可登陆数据库,为了安全起见,登陆后立即修改数据库密码

[root@host01 db]$./mysql -h localhost -u root  -S /db/mysqlmha/data/mysql.sock

update mysql.user set password=PASSWORD('mysql') where user='root' and host='localhost';

flush privileges;

删除用户名或是密码为空的账号

delete from mysql.user where user='';

delete from mysql.user where password='';

10.关闭数据库后重启

[mysql@host01 bin]$ ./mysqladmin -h localhost -u root -p -S /db/mysqlmha/data/mysql.sock shutdown

[mysql@host01 bin]$./mysqld_safe --defaults-file=/db/mysqlmha/conf/my.cnf --user=mysql

11.把mysql加入系统自启动

[root@host01 ~]# more /etc/rc.local

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

/db/mysqlmha/bin/mysqld_safe --defaults-file=/db/mysqlmha/conf/my.cnf --user=mysql &

12. 5.6.34版本有bug,某些表需要重建,点击链接安装部署实施.

http://blog.chinaunix.net/uid-77311-id-5756660.html

centos 7自动启另外一种方式:1.touch /usr/lib/systemd/system/mysql.service

2.该文件内容如下:

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/opt/mysql5640/bin/mysqld_safe --defaults-file=/opt/mysql5640/conf/my.cnf --user=mysql

LimitNOFILE = 5000

#Restart=on-failure

#RestartPreventExitStatus=1

#PrivateTmp=false

3.通过systemctl启动

systemctl start mysql

遇到无法启动的情况下需要做如下操作

[root@localhost bin]# systemctl start mysql

Warning: mysql.service changed on disk. Run 'systemctl daemon-reload' to reload units.

解决办法:

[root@localhost bin]# systemctl daemon-reload

4.启用开启自启动

systemctl enable mysql

5.查看启动状态

systemctl status mysql

my.cnf配置文件内容如下:

[mysql@host01 conf]$ more my.cnf

[mysqld]

port=3306

server-id=1

datadir=/db/mysqlmha/data

socket=/db/mysqlmha/data/mysql.sock

character-set-server=utf8mb4

max_connections = 1500

skip-external-locking

key_buffer_size=16M

max_allowed_packet=16M

myisam_sort_buffer_size=16M

query_cache_size=32M

read_buffer_size=2M

sort_buffer_size=2M

#table_cache=512

#thread_cache=20

#thread_concurrency=4

interactive_timeout=86400

wait_timeout=86400

#log_slow_queries=1

innodb_file_per_table=1

#innodb_additional_mem_pool_size=16M

innodb_buffer_pool_size=128M

innodb_data_home_dir=/db/mysqlmha/ibdata

innodb_data_file_path=ibdata1:100M;ibdata2:100M;ibdata3:100M;ibdata4:100M:autoextend

##这两个参数可以不用指定,要是指定的话,系统启动后会生成ibdata1,ibdata2..4,包括重新生成ibdata1,数据库刚安装的时候系统信息表全部是保留在ibdata1里的,这样的话,这些系统表就会提示不存在.

#innodb_file_io_threads=4

innodb_flush_log_at_trx_commit=2

innodb_lock_wait_timeout=50

innodb_log_buffer_size=128M

innodb_log_file_size=128M

innodb_log_files_in_group=5

innodb_log_group_home_dir=/db/mysqlmha/redolog

innodb_thread_concurrency=8

log_bin_trust_function_creators=1

event_scheduler=1

max_binlog_size=100M

log-bin=/db/mysqlmha/mysqllog/binlog/binlog.bin

slow_query_log_file=/db/mysqlmha/mysqllog/logfile/slow-query.log

long_query_time=1

log-error=/db/mysqlmha/mysqllog/logfile/mysql-err.log

binlog_format=row

expire_logs_days=7

binlog_cache_size=4MB

skip-host-cache

skip-name-resolve

#read-only

skip-slave-start

relay-log-index=/db/mysqlmha/mysqllog/relaylog/slave-relay-bin.index

relay-log=/db/mysqlmha/mysqllog/relaylog/slave-relay

replicate_wild_ignore_table=mysql.%

replicate_wild_ignore_table=information_schema.%

replicate_wild_ignore_table=performance_schema.%  ##主从库都需要配置

slave_net_timeout=60

log_slave_updates=1

##lower_case_table_names=1

##language=/db/mysqlmha/share/english

lc-messages-dir=/db/mysqlmha/share

explicit_defaults_for_timestamp=true

#innodb_stats_persistent=0

#secure-file-priv=/db/mysqloutput

collation-server=utf8mb4_general_ci

init_connect='SET collation_connection = utf8mb4_general_ci'

init_connect='SET NAMES utf8mb4'

transaction-isolation = READ-COMMITTED

[client]

port=3306

socket=/db/mysqlmha/data/mysql.sock

loose-default-character-set = utf8

default-character-set=utf8

[mysql]

no-auto-rehash

port=3306

socket=/db/mysqlmha/data/mysql.sock

[mysqldump]

max_allowed_packet=16M

-- The End --

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值