澳门新萄京官方网站-www.8455.com-澳门新萄京赌场网址

mariadb安装和多实例配置,Yum编译安装MySQL

2019-05-17 作者:数据库网络   |   浏览(157)

一、MySQL数据库的法定网站:

  • https://www.oracle.com/
  • http://dev.mysql.com/doc/refman/5.7/en/linux-installation.html
  •        //不相同版本的设置文书档案和下载能够在那边找

本文介绍mysql各个安装形式(rpm/glibc通用二进制/源码编写翻译)以及多实例配置的章程,没什么本事,算是一篇方法归总作品。

正文目录:
一. mysql单实例安装
  1.1 rpm安装mysql
  1.2通用二进制包安装mysql
    1.二.1初步化数据库
    一.二.2安装后的规范化操作
  1.三编写翻译安装
    1.叁.1编写翻译安装进度
    1.3.2 初始化
    1.3.3 规范化
    一.三.四cmake编写翻译MySQL时的选料表明
二. mysql多实例配置
  二.1mysql多实例配置进程
  二.2提供sysV服务管理脚本
  二.三提供systemd服务管理脚本
3. mariadb安装

正文实例为大家享受CentOS 7.2Yum安装mysql伍.6的办法,供咱们参照他事他说加以调查,具体内容如下

Centos 晋级MySQL版本也许Yum安装Mysql伍.陆

  • 一.从MySQL Yum仓库下载最新的rpm文件:
    http://dev.mysql.com/downloads/repo/yum/
    CentOS 6
    http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
  • 2.yum remove mysql mysql-*
  • 3.mysql-community-release-el6-5.noarch.rpm
  • 4.yum localinstall mysql-community-release-el6-5.noarch.rpm
  • 5.足以因而上边包车型客车命令来认同这些库房被成功增加:
    yum repolist enabled | grep "mysql.-community."
  • 6.yum install mysql-community-server

设置currenttime
http://www.metsky.com/archives/118.html
参照文件:
http://blog.csdn.net/shootyou/article/details/8236886

记得删除老版本的/etc/my.conf,/var/lib/mysql, 或许备份老版本的mysql
要否则恐怕会运营不起来
http://www.th7.cn/db/mysql/201408/66691.shtml

二、MySQL的安装格局:

以下是MySQL常见的二种安装格局:

  • 二进制  rpm   Yum Repository    mysql57-community-release-el7-9.noarch.rpm
  • 二进制  预编译  Generic                        mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
  • 源码包安             Source Code                mysql-5.7.19.tar.gz
  1. 正文的装置境况为centos陆.陆和centos七.2,但大繁多地点都是centos6.陆作为示范示例。
  2. 正文安装MySQL时,它们的运作地方为mysql,数据目录datadir为/mydata/data。
  3. pid文件路线设置为/mydata/data/mysql.pid或/mydata/data/`hostname`.pid。
  4. 由于mariadb和mysql 五各类并不曾太大的例外。因而仅详细体现mysql的设置。最后将轻易提一提mariadb。

  5. mysql单实例安装

本文介绍mysql种种安装格局(rpm/glibc通用贰进制/源码编写翻译)以及多实例配置的秘籍,没什么手艺,算是1篇方法归总文章。

配置CentOS SCLo源

修改用户密码:

update mysql.user set password=password("新密码") where User="root";

flush privileges;


// windows
修改登录密码 MySQL默认没有密码,安装完毕增加密码的重要性是不言而喻的。  
1、命令  /usr/bin/mysqladmin -u root password 'new-password'**  
格式:
mysqladmin -u用户名 -p旧密码 password 新密码**  
2、例子  例1:给root加个密码123456。  
键入以下命令 :  
[root@test1 local]# /usr/bin/mysqladmin -u root password 123456

3、Yum的方法安装MySQL:

  • yum安装mysql 5.7的合法安装格局地址

1、下载安装包

  • *此地址为Mysql 八.0 的安装源个中带有MySQL 伍.七的源,能够在后头步骤修改开放的饭馆: *

2、 设置安装起来意况

暂时先把防火墙关闭保证实验顺利:
[root@host-131 ~]# systemctl stop firewalld 
[root@host-131 ~]# systemctl disable firewalld.service
临时关闭SELlinux:
[root@host-131 ~]# setenforce 0
永久关闭SELinux:
[root@host-131 ~]# sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
查看SELinux状态:
[root@host-131 ~]# getenforce
Disabled

 三、卸载系统自带的数据库(Centos7自带的是maridb)

1.1 rpm包安装mysql

间接yum安装mysql-server就可以。但注意两点:

(一).centos七上,yum暗中认可将安装mariadb。
(2).centos六上,yum暗中认可安装的版本比较老(5.一版),要设置mysql 5.陆或mysql 伍.七,能够从官方下载,也得以行使以下配置的yum源。

release=`awk  -F "[ .]" '{print $4}' /etc/redhat-release`
cat <<eof>/etc/yum.repos.d/mysql.repo
[mysql56]
name=MySQL
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/$release/$basearch/
enabled=1
gpgcheck=0

[mysql57]
name=MySQL
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/$release/$basearch/
enabled=1
gpgcheck=0
eof

除此以外,在sohu镜像站点也提供了mysql的次第rpm版本。地址:http://mirrors.sohu.com/mysql/

还需注意,配置了yum源后装置Mysql将应用mysql-community-*安装各mysql相关包,例如mysql-community-server。

安装完结后,运转mysqld。

shell> service mysqld start      # 或 systemctl start mysqld

譬如开发银行失败,则大概需求开始化MySQL。

shell> mkdir -p /mydata/data
shell> chown -R mysql.mysql /mydata/data
shell> mysql_install_db --datadir=/mydata/data --user=mysql

一经应用mysql_install_db开首化时提示该命令已经取消(5.七版本或许会这么提醒),那么使用上边包车型客车吩咐举行初阶化。

# 初始化时,为root@localhost创建一个临时密码存放在mysql.log中
shell> mysqld --initialize --datadir=/mydata/data --user=mysql
# 初始化时,为root@localhost创建一个空密码
shell> mysqld --initialize-insecure --datadir=/mydata/data --user=mysql

早先化后再开发银行,运转成功后连连数据库并修改root@localhost用户的密码,然后退出。

shell> mysql
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
mysql> q

如若前边使用mysqld --initialize开首化数据库,那么将会为"root@localhost"创立三个密码,那将使得无法直接动用mysql指令连接数据库。能够先从mysql.log中筛选出创立的不时密码,然后再手动修改为"123456"。

shell> grep 'temporary password' /var/log/mysqld.log
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
mysql> q
  1. 本文的安装碰着为centos6.6和centos七.二,但当先三分之1地方都是centos六.六作为示范示例。
  2. 本文安装MySQL时,它们的周转地点为mysql,数据目录datadir为/mydata/data。
  3. pid文件路线设置为/mydata/data/mysql.pid或/mydata/data/`hostname`.pid。
  4. 由于mariadb和mysql 伍层层并从未太大的不等。由此仅详细显示mysql的安装。最终将轻巧提1提mariadb。

  5. mysql单实例安装

[3] 添加 CentOS SCLo Software collections Repository.
[root@linuxprobe~]# yum -y install centos-release-scl-rh centos-release-scl
# set [priority=10]
[root@linuxprobe~]# sed -i -e "s/]$/]npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo
[root@linuxprobe~]# sed -i -e "s/]$/]npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
# for another way, change to [enabled=0] and use it only when needed
[root@linuxprobe~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo
[root@dlp ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo

始建数据库:

 CREATE DATABASE `test2` DEFAULT  CHARACTER SET utf8 COLLATE utf8_general_ci;

可参考:【MySQL解惑笔记】Centos7下卸载深透MySQL数据库

卸载maridb:
[root@host-131 ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@host-131 ~]# yum -y remove mari*
[root@host-131 ~]# rm -rf /var/lib/mysql/*
[root@host-131 ~]# rpm -qa | grep mariadb
[root@host-131 ~]# 

4、修改商旅

[root@host-131 src]# yum rpolist all |grep mysql      //查看所有仓库,并能够看到开启和禁用的仓库
[root@host-131 src]# yum repolist enabled | grep "mysql.*-community.*"  //查看所有开启的仓库,发现现在开启的是MySQL 8.0的,我们需要开启MySQL5.7的仓库
mysql-connectors-community/x86_64 MySQL Connectors Community                  51
mysql-tools-community/x86_64      MySQL Tools Community                       63
mysql80-community/x86_64          MySQL 8.0 Community Server                  17     //k

 开启和关闭不同仓库,官方提供了三种修改方法:

方法一:
shell> sudo yum-config-manager --disable mysql80-community
shell> sudo yum-config-manager --enable mysql57-community

方法二:
shell> sudo dnf config-manager --disable mysql57-community
shell> sudo dnf config-manager --enable mysql56-community

方法三:
我们直接修改Yum源文件:
[root@host-131 ~]# cd /etc/yum.repos.d 
[root@host-131 yum.repos.d]# vim mysql-community.repo 
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1                        //修改为1表示开启
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0                        //修改为0表示关闭
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[root@host-131 yum.repos.d]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community                  51
mysql-tools-community/x86_64      MySQL Tools Community                       63
mysql57-community/x86_64          MySQL 5.7 Community Server                 267    //可以看到5.7存储仓库已经开启

注意:我们应该在任何时候只启用一个发布系列的子存储库。当启用多个发布系列的子存储库时,Yum将使用最新的系列。
通过运行以下命令并检查其输出(对于Fedora,用dnf替换yum),验证是否启用了正确的子库并禁用了它:
[root@host-131 yum.repos.d]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community                  51
mysql-tools-community/x86_64      MySQL Tools Community                       63
mysql57-community/x86_64          MySQL 5.7 Community Server                 267

 5、安装MySQL数据库

[root@host-131 yum.repos.d]# yum -y install mysql-community-server
[root@host-131 ~]# systemctl start mysqld   
[root@host-131 ~]# systemctl enable mysqld   设置开机自启动
[root@host-131 ~]# systemctl status mysqld  查看mysql启动状态

[root@host-131 ~]# ls /var/lib/mysql    (安装后可以看到初始化的数据库)
auto.cnf    client-cert.pem  ibdata1      ibtmp1      mysql.sock.lock     public_key.pem   sys
ca-key.pem  client-key.pem   ib_logfile0  mysql   performance_schema  server-cert.pem
ca.pem      ib_buffer_pool   ib_logfile1  mysql.sock  private_key.pem     server-key.pem

6、第叁遍登入数据库,并安装起首化密码

[root@host-131 ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
发现是禁止访问的

在服务器的初始启动时,由于服务器的数据目录为空:服务器初始化。SSL证书和密钥文件是在数据目录中生成的。
安装并启用了validate_password。
一个超级用户帐户'root'@'localhost被创建。
超级用户的密码被设置并存储在错误日志文件中。要显示它,请使用以下命令:

MySQL5.5之前版本安装后可以直接登录
MySQL5.5自动生成的密码是空的
MySQL5.6是将密码放在root下的
MySQL5.7是将密码放在:
[root@host-131 ~]# grep 'temporary password' /var/log/mysqld.log
2018-05-30T06:34:56.956716Z 1 [Note] A temporary password is generated for root@localhost: xt8S3rWXOL/C
[root@host-131 ~]# 
[root@host-131 ~]# mysql -uroot -p"xt8S3rWXOL/C"
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.7.22
修改密码:
方法一:
[root@host-131 ~]# mysqladmin -uroot -p"xt8S3rWXOL/C" password "Yanglt123."   //密码要满足复杂性要求
[root@host-131 ~]# mysql -uroot -p"Yanglt123."

方法二:

[root@host-131 ~]# grep 'temporary password' /var/log/mysqld.log
2018-05-30T06:34:56.956716Z 1 [Note] A temporary password is generated for root@localhost: xt8S3rWXOL/C
[root@host-131 ~]# 
[root@host-131 ~]# mysql -uroot -p"xt8S3rWXOL/C"

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

 到此数据库安装成功:

源码安装可参看文章:*【Linux运营】LNMP情形布署*

  

一.2 通用二进制包安装mysql

通用二进制包也正是windows中的便携版软件,解压后有个别配置下就可以直接行使,不用安装。

mysql通用二进制版官方下载地址:

  • MySQL 五.陆通用贰进制包下载:
    https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.35-linux-glibc2.12-x86_64.tar.gz
  • MySQL 5.柒通用2进制包下载:
    https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.12-x86_64.tar.gz

里面文件中的glibc二.12象征的是Linux系统的glibc版本要比贰.1二新,能够动用ldd --version查阅glibc版本。在CentOS 陆上glibc暗中认可就是二.12的,所以不用操心。

shell> tar xf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
shell> ln -s /usr/local/mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql

1.1 rpm包安装mysql

直接yum安装mysql-server就可以。但注意两点:

(壹).centos7上,yum暗许将安装mariadb。
(2).centos6上,yum暗许安装的本子比较老(5.一版),要设置mysql 5.陆或mysql 伍.7,能够从官方下载,也得以行使以下配置的yum源。

cat <<eof>/etc/yum.repos.d/mysql.repo
[mysql]
name=MySQL
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
# baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
# baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
# baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0
eof

其它,在sohu镜像站点也提供了mysql的次第rpm版本。地址:http://mirrors.sohu.com/mysql/

还需注意,配置了yum源后安装Mysql将使用mysql-community-*安装各mysql相关包,例如mysql-community-server。

安装完毕后,运维mysqld。

shell> service mysqld start      # 或 systemctl start mysqld

壹旦开发银行退步,则大概要求初步化MySQL。

shell> mkdir -p /mydata/data
shell> chown -R mysql.mysql /mydata/data
shell> mysql_install_db --datadir=/mydata/data --user=mysql

只要采纳mysql_install_db初步化时提示该命令已经遗弃(伍.7版本恐怕会这么提示),那么使用下边包车型大巴授命进行开端化。

# 初始化时,为root@localhost创建一个临时密码存放在mysql.log中
shell> mysqld --initialize --datadir=/mydata/data --user=mysql
# 初始化时,为root@localhost创建一个空密码
shell> mysqld --initialize-insecure --datadir=/mydata/data --user=mysql

早先化后再开发银行,运营成功后总是数据库并修改root@localhost用户的密码,然后退出。

shell> mysql
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
mysql> q

举个例子前面使用mysqld --initialize发轫化数据库,那么将会为"root@localhost"创立三个密码,这将使得无法间接选择mysql一声令下连接数据库。能够先从mysql.log中筛选出创造的不时密码,然后再手动修改为"123456"。

shell> grep 'temporary password' /var/log/mysqld.log
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
mysql> q

yum安装MySQL

修改my.cnf文件(mysql 收缩内部存款和储蓄器使用)

# Example mysql config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld deamon
# doesn't use much resources.
#
# You can copy this file to
# /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is /var/lib/mysql) or
# ~/.my.cnf to set user-specific options.
#
# One can in this file use all long options that the program supports.
# If you want to know which options a program support, run the program
# with --help option.

# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /var/run/mysqld/mysqld.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port = 3306
socket = /var/run/mysqld/mysqld.sock
character-set-server=utf8

key_buffer = 16K
query_cache_limit = 256K
query_cache_size = 4M
max_allowed_packet = 1M

max_connections = 16
thread_concurrency = 2

sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 64K
performance_schema_max_table_instances=400

table_definition_cache=400

table_open_cache=256

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
#safe-updates

[isamchk]
key_buffer = 8M
sort_buffer_size = 8M

[myisamchk]
key_buffer = 8M
sort_buffer_size = 8M

[mysqlhotcopy]
interactive-timeout

# Uncomment the following if you want to log updates
#log-bin

# Uncomment the following if you are NOT using BDB tables
#skip-bdb

# Uncomment the following if you are using Innobase tables
#innodb_data_file_path = ibdata1:100M
#innodb_data_home_dir = /var/lib/mysql/
#innodb_log_group_home_dir = /var/lib/mysql/
#innodb_log_arch_dir = /var/lib/mysql/
#set-variable = innodb_mirrored_log_groups=1
#set-variable = innodb_log_files_in_group=3
#set-variable = innodb_log_file_size=5M
#set-variable = innodb_log_buffer_size=8M
#innodb_flush_log_at_trx_commit=1
#innodb_log_archive=0
#set-variable = innodb_buffer_pool_size=16M
#set-variable = innodb_additional_mem_pool_size=2M
#set-variable = innodb_file_io_threads=4
#set-variable = innodb_lock_wait_timeout=50

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

壹.二.1 初步化数据库

不利用rpm包安装,就供给对mysql进行初步化以创立一些文书、库和点名一些参数。但在开头化mysql前,要优先做一些操作。

shell> mkdir -p /mydata/data
shell> useradd -r -s /sbin/nologin mysql
shell> chown -R mysql.mysql /usr/local/mysql
shell> chown -R mysql.mysql /mydata/data
shell> cd /usr/local/mysql
shell> scripts/mysql_install_db --datadir=/mydata/data --user=mysql
shell> chown -R root.root /usr/local/mysql

执行mysql_install_db时会在/tmp下开创一时表,所以mysql用户要求对/tmp有写权限,不然施行实例开始化脚本时大概会报类似下边包车型地铁荒唐:
ERROR: 1 Can't create/write to file '/tmp/#sql_7a0e_0.MYI' (Errcode: 13)
那表达未有写权限,所以须求修改/tmp目录的权位:

chmod 1777 /tmp

同样,mysql_install_db发端时只要提醒已放任,则选拔如下方法:

bin/mysqld --initialize-insecure --datadir=/mydata/data --user=mysql

初阶化完毕后,提供配置文件和劳动运营脚本。

shell> cp -a support-files/mysql.server /etc/init.d/mysqld
shell> cp -a support-files/my-default.cnf /etc/my.cnf  

# 修改my.cnf的datadir
shell> vim /etc/my.cnf 
[mysqld]
datadir=/mydata/data

尽管是centos7,则提供如下服务运行脚本(如有要求,修改pid文件路线)。

shell> cat /usr/lib/systemd/system/mysqld.service
[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

Type=forking

PIDFile=/var/run/mysqld/mysqld.pid

# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0

# Start main service
ExecStart=/usr/local/mysql-5.7.19/bin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS

# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql

# Sets open_files_limit
LimitNOFILE = 5000

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false

修改"root@localhost"密码。

shell> mysql
mysql> alter user 'root'@'localhost' identified by '123456';
mysql> q

一.二 通用2进制包安装mysql

通用贰进制包也正是windows中的便携版软件,解压后有些配置下就足以直接选用,不用安装。

mysql通用二进制版官方下载地址:

  • MySQL 五.陆通用二进制包下载:
    https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.35-linux-glibc2.12-x86_64.tar.gz
  • MySQL 五.柒通用二进制包下载:
    https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.12-x86_64.tar.gz

个中文件中的glibc贰.1贰表示的是Linux系统的glibc版本要比二.1二新,能够应用ldd --version翻看glibc版本。在CentOS 陆上glibc私下认可就是二.1二的,所以不用操心。

shell> tar xf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
shell> ln -s /usr/local/mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
# 安装mysql
[root@linuxprobe~]# yum --enablerepo=centos-sclo-rh -y install rh-mysql56-mysql-server
# 加载环境变量
[root@linuxprobe ~]# scl enable rh-mysql56 bash
[root@linuxprobe ~]# mysql -V 
mysql Ver 14.14 Distrib 5.6.26, for Linux (x86_64) using EditLine wrapper
[root@linuxprobe ~]# which mysql 
/opt/rh/rh-mysql56/root/usr/bin/mysql
# 设置mysql开机自启动
root@linuxprobe ~]# vi /etc/profile.d/rh-mysql56.sh
#!/bin/bash
source /opt/rh/rh-mysql56/enable
export X_SCLS="`scl enable rh-mysql56 'echo $X_SCLS'`"




[4] Enable MySQL 5.6 and Configure initial settings.
[root@linuxprobe ~]# vi /etc/opt/rh/rh-mysql56/my.cnf.d/mysql-server.cnf
# add follows within [mysqld] section
[mysqld]
character-set-server=utf8
[root@linuxprobe ~]# systemctl start rh-mysql56-mysqld
[root@linuxprobe ~]# systemctl enable rh-mysql56-mysqld
[root@linuxprobe ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
 SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
# set root password
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
# remove anonymous users
Remove anonymous users? [Y/n] y
 ... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
# disallow root login remotely
Disallow root login remotely? [Y/n] y
 ... Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
# remove test database
Remove test database and access to it? [Y/n] 
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
# reload privilege tables
Reload privilege tables now? [Y/n] y
 ... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!




[root@linuxprobe ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 13
Server version: 5.6.26 MySQL Community Server (GPL)

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> select user,host,password from mysql.user; 
 ------ ----------- ------------------------------------------- 
| user | host | password     |
 ------ ----------- ------------------------------------------- 
| root | localhost | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 |
| root | 127.0.0.1 | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 |
| root | ::1 | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 |
 ------ ----------- ------------------------------------------- 
3 rows in set (0.00 sec)
mysql> show databases; 
 -------------------- 
| Database  |
 -------------------- 
| information_schema |
| mysql  |
| performance_schema |
 -------------------- 
3 rows in set (0.00 sec)
mysql> exit
Bye

字符编码

查看字符编码: status

1.关于MySQL字符集
MySQL的字符集支持(Character Set Support)有两个方面: 
 字符集(Character set)和排序方式(Collation)。
MySQL对于字符集的支持细化到四个层次: 服务器(server),数据库(database),数据表(table)和连接(connection)。
MySQL对于字符集的指定可以细化到一个数据库,一张表,一列,应该用什么字符集。
2.查看MySQL字符集
2.1.查看字符集的设置
mysql> show variables like 'character_set_%';

2.2.查看字符集排序设置
mysql> show variables like 'collation_%';

3.修改MySQL字符集
3.1修改服务器级别字符集
a.临时修改
mysql>SET GLOBAL character_set_server=utf8;
b.永久修改
 打开/etc/mysql/my.cnf,在[mysqld]后添加character-set-server=utf8
3.2修改数据库级 
a. 临时更改
mysql>SET GLOBAL character_set_database=utf8;
b. 永久更改
改了服务器级就可以了
3.3修改表级 
mysql>ALTER TABLE table_name DEFAULT CHARSET utf8; 更改了后永久生效
3.4修改列级修改示例
mysql>ALTER TABLE `products` CHANGE `products_model` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL; 更改了后永久生效 
3.5更改连接字符集
 a. 临时更改:mysql> SET GLOBAL character_set_client;
b. 永久更改:打开/etc/mysql/my.cnf,在[client]后添加default-character-set=utf8
Notice:3.1和3.5需要重启mysql:   service mysql restart

1.2.二 安装后的规范化操作

编写翻译安装或通用贰进制安装后,一般都须求做一些附加的操作,包蕴安装碰到变量、输出头文件和库文件、设置man路线。

echo "export PATH=/usr/local/mysql/bin:$PATH" >/etc/profile.d/mysql.sh
chmod  x /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
echo "MANPATH /usr/local/mysql/man" >>/etc/man.config

echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
ldconfig
ln -s /usr/local/mysql/include /usr/include/mysql

一.2.一 起始化数据库

不应用rpm包安装,就需求对mysql进行伊始化以创造一些文本、库和点名一些参数。但在伊始化mysql前,要先行做一些操作。

shell> mkdir -p /mydata/data
shell> useradd -r -s /sbin/nologin mysql
shell> chown -R mysql.mysql /usr/local/mysql
shell> chown -R mysql.mysql /mydata/data
shell> cd /usr/local/mysql
shell> scripts/mysql_install_db --datadir=/mydata/data --user=mysql
shell> chown -R root.root /usr/local/mysql

执行mysql_install_db时会在/tmp下创办一时表,所以mysql用户需求对/tmp有写权限,不然施行实例初步化脚本时或许会报类似上面的荒谬:
ERROR: 1 Can't create/write to file '/tmp/#sql_7a0e_0.MYI' (Errcode: 13)
那注明没有写权限,所以要求修改/tmp目录的权能:

chmod 1777 /tmp

同样,mysql_install_db发端时只要提示已放弃,则使用如下方法:

bin/mysqld --initialize-insecure --datadir=/mydata/data --user=mysql

初始化完结后,提供配置文件和劳务运行脚本。

shell> cp -a support-files/mysql.server /etc/init.d/mysqld
shell> cp -a support-files/my-default.cnf /etc/my.cnf  

# 修改my.cnf的datadir
shell> vim /etc/my.cnf 
[mysqld]
datadir=/mydata/data

要是是centos七,则提供如下服务运营脚本(如有须要,修改pid文件路线)。

shell> cat /usr/lib/systemd/system/mysqld.service
[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

Type=forking

PIDFile=/var/run/mysqld/mysqld.pid

# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0

# Start main service
ExecStart=/usr/local/mysql-5.7.19/bin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS

# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql

# Sets open_files_limit
LimitNOFILE = 5000

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false

修改"root@localhost"密码。

shell> mysql
mysql> alter user 'root'@'localhost' identified by '123456';
mysql> q

翻开防火墙

重起mysql

service mysqld restart

转:http://www.blogjava.net/nkjava/archive/2014/11/21/420406.html

1.三 编译源码安装mysql

建议别没事找事,尝试编写翻译装MySQL,完全部是吃力不讨好的事。假如的确要编写翻译安装,把my.cnf、服务管理脚本、编译选项等关系到运营文件路径的项保障同等,比方pid文件、socket文件、datadir路径、log文件。并保管mysql涉及到的目录全体者和所属组都以mysql,比如默许的pid路线/var/run/mysql/。

mysql源码包下载地址:

  • MySQL 伍.陆源码包下载:
    https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.37.tar.gz

  • MySQL 5.七源码包下载:
    https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19.tar.gz

一.二.二 安装后的标准化操作

编写翻译安装或通用2进制安装后,一般都供给做一些卓殊的操作,包括安装意况变量、输出头文件和库文件、设置man路线。

echo "export PATH=/usr/local/mysql/bin:$PATH" >/etc/profile.d/mysql.sh
chmod  x /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
echo "MANPATH /usr/local/mysql/man" >>/etc/man.config

echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
ldconfig
ln -s /usr/local/mysql/include /usr/include/mysql
[root@linuxprobe ~]# firewall-cmd –add-service=MySQL –permanent 
success 
[root@linuxprobe ~]# firewall-cmd –reload 
success

1.叁.一 编写翻译安装进程

至于编写翻译选项,见下文。

应用以下命令安装mysql 伍.陆。

yum -y install ncurses-devel cmake
tar xf ~/mysql-5.6.37.tar.gz
cd ~/mysql-5.6.37
cmake . 
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.37 
-DDEFAULT_CHARSET=utf8 
-DDEFAULT_COLLATION=utf8_general_ci 
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii 
-DENABLED_LOCAL_INFILE=ON 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_FEDERATED_STORAGE_ENGINE=1 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 
-DWITH_FAST_MUTEXES=1 
-DWITH_EMBEDDED_SERVER=1 
-DWITH_SSL=bundled 
-DWITH_DEBUG=0 
make
make install

运用以下命令安装mysql 五.七。比上述多了最终3个boost相关设置项,不安装此项只怕会cmake退步。

yum -y install ncurses-devel cmake
tar xf ~/mysql-5.7.19.tar.gz
cd ~/mysql-5.7.19
cmake . 
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.19 
-DDEFAULT_CHARSET=utf8 
-DDEFAULT_COLLATION=utf8_general_ci 
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii 
-DENABLED_LOCAL_INFILE=ON 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_FEDERATED_STORAGE_ENGINE=1 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 
-DWITH_FAST_MUTEXES=1 
-DWITH_EMBEDDED_SERVER=1 
-DWITH_SSL=bundled 
-DWITH_DEBUG=0 
-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
make
make install

设若是centos7,则拉长壹项-DWITH_SYSTEMD=1,这会提供systemd脚本。

只顾,上述编写翻译选项中绝非提供sysconfdir、datadir、pidfile和socket等mysql启动时文件类设置选项。纵然可以设置,但没需要,而且在做多实例的时候恐怕会冒出难题。可是,能够设想加上MYSQL_UNIX_ADDR项来设置socket路线,因为不设置的话其会利用暗许的/tmp/mysql.sock。

一.三 编写翻译源码安装mysql

建议别没事找事,尝试编写翻译装MySQL,完全部是吃力不讨好的事。若是真的要编写翻译安装,把my.cnf、服务管理脚本、编写翻译选项等关乎到运营文件路线的项保证同等,举例pid文件、socket文件、datadir路径、log文件。并确定保障mysql涉及到的目录全体者和所属组都以mysql,举例暗中同意的pid路线/var/run/mysql/。

mysql源码包下载地址:

  • MySQL 五.六源码包下载:
    https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.37.tar.gz

  • MySQL 五.7源码包下载:
    https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19.tar.gz

同样使用yum在vdevops.org上面安装mysql,安装步骤仿照效法上面

1.3.2 初始化

shell> ln -s /usr/local/mysql-5.6.37 /usr/local/mysql
shell> cd /usr/local/mysql
shell> useradd -r -s /sbin/nologin mysql
shell> mkdir -p /mydata/data
shell> chown -R mysql.mysql /mydata/data
shell> chmod o-rx /mydata/data
shell> chown -R mysql.mysql /usr/local/mysql
shell> scripts/mysql_install_db --user=mysql --datadir=/mydata/data
shell> cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
shell> cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
shell> chown -R root.root /usr/local/mysql
# 修改my.cnf的datadir、socket、log和pid路径。
shell> vim /etc/my.cnf 
[mysqld]
datadir=/mydata/data
socket=/tmp/mysql.sock
[mysqld_safe]
log-error=/mydata/data/mysql.log
pid-file=/mydata/data/mysqld.pid

注:mysql 5.7提议选取如下语句举办开首化。

/usr/local/mysql/bin/mysqld --initialize-insecure --datadir=/mydata/data --user=mysql

如果是centos7,则提供systemd风格的服务管理脚本,并认不过不是要修改pid文件路线。

1.三.一 编译安装进度

有关编写翻译选项,见下文。

行使以下命令安装mysql 伍.六。

yum -y install ncurses-devel cmake
tar xf ~/mysql-5.6.37.tar.gz
cd ~/mysql-5.6.37
cmake . 
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.37 
-DDEFAULT_CHARSET=utf8 
-DDEFAULT_COLLATION=utf8_general_ci 
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii 
-DENABLED_LOCAL_INFILE=ON 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_FEDERATED_STORAGE_ENGINE=1 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 
-DWITH_FAST_MUTEXES=1 
-DWITH_EMBEDDED_SERVER=1 
-DWITH_SSL=bundled 
-DWITH_DEBUG=0 
make
make install

使用以下命令安装mysql 5.柒。比上述多了最终1个boost相关设置项,不设置此项恐怕会cmake战败。

yum -y install ncurses-devel cmake
tar xf ~/mysql-5.7.19.tar.gz
cd ~/mysql-5.7.19
cmake . 
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.19 
-DDEFAULT_CHARSET=utf8 
-DDEFAULT_COLLATION=utf8_general_ci 
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii 
-DENABLED_LOCAL_INFILE=ON 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_FEDERATED_STORAGE_ENGINE=1 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 
-DWITH_FAST_MUTEXES=1 
-DWITH_EMBEDDED_SERVER=1 
-DWITH_SSL=bundled 
-DWITH_DEBUG=0 
-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
make
make install

比如是centos7,则增进一项-DWITH_SYSTEMD=1,那会提供systemd脚本。

在意,上述编写翻译选项中从未提供sysconfdir、datadir、pidfile和socket等mysql运维时文件类设置选项。即便能够安装,但没要求,而且在做多实例的时候只怕会师世难题。可是,可以思虑加上MYSQL_UNIX_ADDR项来设置socket路线,因为不安装的话其会选拔私下认可的/tmp/mysql.sock。

MySQL 主从

1.3.3 规范化

输出头文件、库文件,设置PATH境遇变量,设置man路线。

echo "export PATH=/usr/local/mysql/bin:$PATH" >/etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
chmod  x /etc/profile.d/mysql.sh
echo "MANPATH /usr/local/mysql/man" >>/etc/man.config
echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
ldconfig
ln -s /usr/local/mysql/include /usr/include/mysql

1.3.2 初始化

shell> ln -s /usr/local/mysql-5.6.37 /usr/local/mysql
shell> cd /usr/local/mysql
shell> useradd -r -s /sbin/nologin mysql
shell> mkdir -p /mydata/data
shell> chown -R mysql.mysql /mydata/data
shell> chmod o-rx /mydata/data
shell> chown -R mysql.mysql /usr/local/mysql
shell> scripts/mysql_install_db --user=mysql --datadir=/mydata/data
shell> cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
shell> cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
shell> chown -R root.root /usr/local/mysql
# 修改my.cnf的datadir、socket、log和pid路径。
shell> vim /etc/my.cnf 
[mysqld]
datadir=/mydata/data
socket=/tmp/mysql.sock
[mysqld_safe]
log-error=/mydata/data/mysql.log
pid-file=/mydata/data/mysqld.pid

注:mysql 伍.七建议使用如下语句举办发轫化。

/usr/local/mysql/bin/mysqld --initialize-insecure --datadir=/mydata/data --user=mysql

如果是centos7,则提供systemd风格的劳动管理脚本,并认但是不是要修改pid文件路线。

Master端:linuxprobe

1.三.四 cmake编写翻译MySQL时的选料表达

1.3.3 规范化

输出头文件、库文件,设置PATH遇到变量,设置man路线。

echo "export PATH=/usr/local/mysql/bin:$PATH" >/etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
chmod  x /etc/profile.d/mysql.sh
echo "MANPATH /usr/local/mysql/man" >>/etc/man.config
echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
ldconfig
ln -s /usr/local/mysql/include /usr/include/mysql
[root@linuxprobe~]# vi /etc/opt/rh/rh-mysql56/my.cnf.d/mysql-server.cnf
[mysqld]
# add follows in [mysqld] section : get binary logs
log-bin=mysql-bin
# define uniq server ID
server-id=101
[root@linuxprobe ~]# mysql -u root -p 
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.6.26-log MySQL Community Server (GPL)
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> grant replication slave on *.* to replica@'%' identified by 'password';
Query OK, 0 rows affected (0.07 sec)
mysql> flush privileges; 
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye

Installation Layout Options

  • -DCMAKE_INSTALL_PREFIX=dir_name   # MySQL的装置地点
  • -DINSTALL_PLUGINDIR=dir_name      # 插件安装的目录
  • -DMYSQL_DATADIR=dir_name        # MySQL的data dir
  • -DSYSCONFDIR=dir_name        # MySQL暗许的陈设文件(my.cnf)路线
  • -DTMPDIR=dir_name          # 不常文件存放路线,在MySQL伍.六.1六中才起来提供该选项

一.三.四 cmake编写翻译MySQL时的选用表明

翻开防火墙

Storage Engine Options

积累引擎是插件式的,可被静态编写翻译到MySQL服务中,也能够动态编写翻译成模块,编译成模块时索要利用INSTALL PLUGIN话语或然--plugin-load选料来启用。但一些插件是固定的,不能够内定是静态编写翻译如故动态编写翻译。

InnoDB,MyISAM,ME本田CR-VGE,MEMO奇骏Y和CSV存款和储蓄引擎总是默许静态编写翻译到MySQL服务中的,在编译安装的时候无需显式钦赐它们。

编写翻译存款和储蓄引擎的时候,使用-DWITH_enginename_STORAGE_ENGINE=1代表静态编写翻译到MySQL。可选的斯特林发动机有:A昂科雷C失眠E、BLACKHOLE、EXAMPLE、FEDERATED、PARTITION(分区支持引擎)、PE昂科威FSCHEMA(Performance Schema)。如:

-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1

使用-WITHOUT_enginename_STORAGE_ENGINE=1表示显式的化解这么些引擎,即强制不应用它们。如:

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
-DWITHOUT_FEDERATED_STORAGE_ENGINE=1
-DWITHOUT_PARTITION_STORAGE_ENGINE=1

-DWITH_enginename_STORAGE_ENGINE-WITHOUT_enginename_STORAGE_ENGINE都并未有点名某个引擎的话,这几个引擎暗中同意动态编写翻译成模块,要是无法动态编写翻译成模块则不编写翻译。

Installation Layout Options

  • -DCMAKE_INSTALL_PREFIX=dir_name   # MySQL的设置地点
  • -DINSTALL_PLUGINDIR=dir_name      # 插件安装的目录
  • -DMYSQL_DATADIR=dir_name        # MySQL的data dir
  • -DSYSCONFDIR=dir_name        # MySQL暗中同意的陈设文件(my.cnf)路线
  • -DTMPDIR=dir_name          # 不经常文件存放路线,在MySQL5.6.1陆中才起来提供该选项
[root@linuxprobe ~]# firewall-cmd –add-service=mysql –permanent 
success 
[root@linuxprobe ~]# firewall-cmd –reload 
success

Feature Options

  • -DDEFAULT_CHARSET=charset_name

安装默许字符集,默感觉latin一。比方,binary,ascii,big五,gb231二,gbk,latin一,latin二,latin5,latin7,utf8。

在cmake/character_sets.cmake文件中的CHA福睿斯SETS_AVAILABLE定义了允许行使的字符集列表。

字符集的安装能够在MySQL服务运维的时候使用"--character_set_server"选项来钦点。

  • -DDEFAULT_COLLATION=collation_name

安装私下认可的排序规则。默许排序规则为latin壹_swedish_ci。使用SHOW COLLATION话语能够查看每一种字符集能够行使的排序规则。

排序规则的装置能够在MySQL服务运转的时候使用--collation_server慎选来内定。

  • -DENABLED_LOCAL_INFILE=bool

Whether to enable LOCAL capability in the client library for LOAD DATA INFILE.
This option controls client-side LOCAL capability, but the capability can be set on the server side at server startup with the --local-infile option.

  • -DMYSQL_TCP_PORT=port_num

点名MySQL的TCP端口,暗许是330陆。能够在起步服务时采用--port选项钦点。

  • -DMYSQL_UNIX_ADDR=file_name

点名MySQL的套接字路线,必须是相对路线,暗中认可是/tmp/mysql.sock。能够在开发银行服务时行使--port选项钦命。

  • -DWITH_EXTRA_CHARSETS=name
    Which extra character sets to include:

    • all: All character sets. This is the default.
    • complex: Complex character sets.
    • none: No extra character sets.
  • -DWITH_INNODB_MEMCACHED=bool

Whether to generate memcached shared libraries (libmemcached.so and innodb_engine.so).

  • -DWITH_SSL={ssl_type|path_name}
    The type of SSL support to include (if any) or the path name to the OpenSSL installation to use.

    • ssl_type can be one of the following values:
      • no: No SSL support. This is the default before MySQL 5.6.6. As of 5.6.6, this is no longer a permitted value and the default is bundled.
      • yes: Use the system SSL library if present, else the library bundled with the distribution.
      • bundled: Use the SSL library bundled with the distribution. This is the default as of MySQL 5.6.6.
      • system: Use the system SSL library.
    • path_name, permitted for MySQL 5.6.7 and after, is the path name to the OpenSSL installation to use. Using this can be preferable to using the ssl_type value of system, for it can prevent CMake from detecting and using an older or incorrect OpenSSL version installed on the system. (Another permitted way to do the same thing is to set the CMAKE_PREFIX_PATH option to path_name.).
  • -DWITH_ZLIB=zlib_type

    • bundled: Use thezliblibrary bundled with the distribution. This is the default.
    • system: Use the system zlib library.

Storage Engine Options

积攒引擎是插件式的,可被静态编写翻译到MySQL服务中,也得以动态编写翻译成模块,编写翻译成模块时索要选用INSTALL PLUGIN言语大概--plugin-load分选来启用。但一些插件是一向的,不能内定是静态编译如故动态编写翻译。

InnoDB,MyISAM,MELacrosseGE,MEMO科雷傲Y和CSV存款和储蓄引擎总是暗中认可静态编写翻译到MySQL服务中的,在编写翻译安装的时候无需显式内定它们。

编写翻译存款和储蓄引擎的时候,使用-DWITH_enginename_STORAGE_ENGINE=1表示静态编写翻译到MySQL。可选的外燃机有:A途胜C生殖器疱疹E、BLACKHOLE、EXAMPLE、FEDERATED、PARTITION(分区帮忙引擎)、PEQashqaiFSCHEMA(Performance Schema)。如:

-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1

使用-WITHOUT_enginename_STORAGE_ENGINE=1意味着显式的清除那几个引擎,即强制不选拔它们。如:

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
-DWITHOUT_FEDERATED_STORAGE_ENGINE=1
-DWITHOUT_PARTITION_STORAGE_ENGINE=1

-DWITH_enginename_STORAGE_ENGINE-WITHOUT_enginename_STORAGE_ENGINE都尚未点名有些引擎的话,那么些引擎暗中认可动态编写翻译成模块,假如不能够动态编写翻译成模块则不编写翻译。

Slave端:vdevops

二. mysql多实例配置

mysql可以兑现多实例,但因为多实例会共用服务器能源,导致财富争用,在某实例某说话能源占用好多时(高并发、慢查询),别的的实例会见对震慑。

不论是rpm安装、通用二进制安装依旧编写翻译安装,都有二种格局达成多实例。

  1. 共用配备文件
    在my.cnf中配置四个"[mysqldN]",N是贰个数字,表示MySQL服务。
    启动和停止的时候利用mysqld_multi {start|stop|restart} N。N能够是单个数字,也能够是逗号分隔的四个数字,还能是短横线表示的限量数字。纵然不是rpm包安装的,则mysqld_multi文件的门路在support-files中,将其copy到/etc/init.d下就可以(未有原生态的systemd多实例服务管理脚本)。

    mysqld_multi start 1,2,4-6
    
  2. 独自的陈设文件和开发银行程序(推荐)
    MySQL只需安装一次,即差别实例使用同1安装程序。但每一个实例使用单独的安排文件、服务管理脚本、datadir目录和socket,并且启动与停止mysqld服务时索要钦点套接字文件。

Feature Options

  • -DDEFAULT_CHARSET=charset_name

设置暗中认可字符集,默以为latin一。举例,binary,ascii,big5,gb231二,gbk,latin1,latin二,latin5,latin⑦,utf八。

在cmake/character_sets.cmake文件中的CHA哈弗SETS_AVAILABLE定义了同意行使的字符集列表。

字符集的设置能够在MySQL服务运营的时候利用"--character_set_server"选项来钦定。

  • -DDEFAULT_COLLATION=collation_name

设置暗许的排序规则。暗中同意排序规则为latin一_swedish_ci。使用SHOW COLLATION说话能够查阅每个字符集能够应用的排序规则。

排序规则的装置能够在MySQL服务运营的时候使用--collation_server慎选来钦定。

  • -DENABLED_LOCAL_INFILE=bool

Whether to enable LOCAL capability in the client library for LOAD DATA INFILE.
This option controls client-side LOCAL capability, but the capability can be set on the server side at server startup with the --local-infile option.

  • -DMYSQL_TCP_PORT=port_num

点名MySQL的TCP端口,私下认可是3306。可以在起步服务时利用--port选项钦赐。

  • -DMYSQL_UNIX_ADDR=file_name

点名MySQL的套接字路线,必须是相对路线,暗中同意是/tmp/mysql.sock。能够在运行服务时利用--port选项钦定。

  • -DWITH_EXTRA_CHARSETS=name
    Which extra character sets to include:

    • all: All character sets. This is the default.
    • complex: Complex character sets.
    • none: No extra character sets.
  • -DWITH_INNODB_MEMCACHED=bool

Whether to generate memcached shared libraries (libmemcached.so and innodb_engine.so).

  • -DWITH_SSL={ssl_type|path_name}
    The type of SSL support to include (if any) or the path name to the OpenSSL installation to use.

    • ssl_type can be one of the following values:
      • no: No SSL support. This is the default before MySQL 5.6.6. As of 5.6.6, this is no longer a permitted value and the default is bundled.
      • yes: Use the system SSL library if present, else the library bundled with the distribution.
      • bundled: Use the SSL library bundled with the distribution. This is the default as of MySQL 5.6.6.
      • system: Use the system SSL library.
    • path_name, permitted for MySQL 5.6.7 and after, is the path name to the OpenSSL installation to use. Using this can be preferable to using the ssl_type value of system, for it can prevent CMake from detecting and using an older or incorrect OpenSSL version installed on the system. (Another permitted way to do the same thing is to set the CMAKE_PREFIX_PATH option to path_name.).
  • -DWITH_ZLIB=zlib_type

    • bundled: Use thezliblibrary bundled with the distribution. This is the default.
    • system: Use the system zlib library.
[root@vdevops~]# vi /etc/opt/rh/rh-mysql56/my.cnf.d/mysql-server.cnf
[mysqld]
# add follows in [mysqld] section : get binary logs
log-bin=mysql-bin
# define server ID (different one from Master Host)
server-id=102
# read only
read_only=1
# define own hostname
report-host=node01.srv.world
[root@vdevops~]# systemctl restart rh-mysql56-mysqld

2.一 mysql多实例配置进程

正文介绍第1种方法,并运用rpm包安装的mysql实现多实例。再一次证实,无论接纳何种格局安装mysql,都足以完毕多实例,其实看驾驭下边配置的进程就知晓了。

创造并安装datadir,并早先化、分别提供配置文件。

shell> mkdir -p /mydata/{3306,3307}/data
shell> chown -R mysql.mysql /mydata/{3306,3307}/data
shell> mysql_install_db --datadir=/mydata/3306/data --user=mysql
shell> mysql_install_db --datadir=/mydata/3307/data --user=mysql
shell> cp /etc/my.cnf /mydata/3306/my.cnf
shell> cp /etc/my.cnf /mydata/3307/my.cnf

1经是安装mysql 伍.7的多实例,则早先化时选取如下命令替换上边包车型客车mysql_install_db

shell> mysqld --initialize-insecure --datadir=/mydata/3306/data --user=mysql
shell> mysqld --initialize-insecure --datadir=/mydata/3307/data --user=mysql

分别修改八个布局文件。

#以下是3306实例的配置文件要修改的部分。
shell> vim /mydata/3306/my.cnf
[mysqld]
port=3306
datadir=/mydata/3306/data
socket=/mydata/3306/data/mysql.sock
server_id=1
[mysqld_safe]
log-error=/mydata/3306/data/mysqld.log
pid-file=/mydata/3306/data/mysqld.pid

#以下是3307实例的配置文件要修改部分。
shell> vim /mydata/3307/my.cnf
[mysqld]
port=3307
datadir=/mydata/3307/data
socket=/mydata/3307/data/mysql.sock
server_id=2
[mysqld_safe]
log-error=/mydata/3307/data/mysqld.log
pid-file=/mydata/3307/data/mysqld.pid

二. mysql多实例配置

mysql能够达成多实例,但因为多实例会共用服务器能源,导致能源争用,在某实例某说话财富占用诸多时(高并发、慢查询),其余的实例会惨遭震慑。

任凭rpm安装、通用2进制安装仍旧编写翻译安装,都有三种艺术完毕多实例。

  1. 共用配备文件
    在my.cnf中配置八个"[mysqldN]",N是几个数字,表示MySQL服务。
    启动和停止的时候利用mysqld_multi {start|stop|restart} N。N能够是单个数字,也足以是逗号分隔的八个数字,还足以是短横线表示的限量数字。假设不是rpm包安装的,则mysqld_multi文件的不二等秘书籍在support-files中,将其copy到/etc/init.d下就可以(未有原生态的systemd多实例服务管理脚本)。

    mysqld_multi start 1,2,4-6
    
  2. 单身的安排文件和运转程序(推荐)
    MySQL只需安装3遍,即分歧实例使用同样安装程序。但种种实例使用单独的安排文件、服务管理脚本、datadir目录和socket,并且启动和停止mysqld服务时须求内定套接字文件。

Master端:备份数据库

二.二 提供sysV服务管理脚本

再分别提供劳动管理脚本。

  • 以下是330陆实例的管住脚本/etc/init.d/mysqld330六,内容改变自原有管理脚本/etc/init.d/mysqld。
  • 是因为本身的示范中mysql是应用rpm安装,所以mysql的basedir为/usr,倘若是编写翻译安装或通用2进制安装,则对应修改上边脚本中的basedir变量。
  • 上面包车型地铁datadir变量设置为/mydata/$port/data。请务必和地点的发轫化设置和配置文件中安装的同样。
  • 将此管理脚本复制为/etc/init.d/mysqld330柒,再修改下port=330七就能够作为330柒实例的服务处理脚本。
  • 此脚本不会早先化mysql(作者把这一部分代码删了)创设实例,所以运转服务前必须先开首化好相应的mysql实例。
  • 上面包车型地铁剧本就可以作为多实例服务管理脚本,也足以看做单实例服务管理脚本,只需将脚本名称改壹改就能够。
#!/bin/sh
#
# mysqld    This shell script takes care of starting and stopping
#        the MySQL subsystem (mysqld).
#
# chkconfig: 345 64 36
# description:    MySQL database server.
# processname: mysqld

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

basedir=/usr
exec="$basedir/bin/mysqld_safe"
prog="mysqld"
port=3306
datadir="/mydata/$port/data"
socketfile="$datadir/mysql.sock"
errlogfile="$datadir/mysqld.log"
mypidfile="$datadir/mysqld.pid"
cnf="/mydata/$port/my.cnf"

# Set timeouts here so they can be overridden from /etc/sysconfig/mysqld
STARTTIMEOUT=120
STOPTIMEOUT=60

# Set in /etc/sysconfig/mysqld, will be passed to mysqld_safe
MYSQLD_OPTS=

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/$prog

case $socketfile in
    /*) adminsocket="$socketfile" ;;
     *) adminsocket="$datadir/$socketfile" ;;
esac

start(){
    [ -x $exec ] || exit 5
    # check to see if it's already running
    RESPONSE=$(/usr/bin/mysqladmin --no-defaults --socket="$adminsocket" --user=UNKNOWN_MYSQL_USER ping 2>&1)
    if [ $? = 0 ]; then
    # already running, do nothing
    action $"Starting $prog: " /bin/true
    ret=0
    elif echo "$RESPONSE" | grep -q "Access denied for user"
    then
    # already running, do nothing
    action $"Starting $prog: " /bin/true
    ret=0
    else
    # Now start service
    $exec $MYSQLD_OPTS --defaults-file="$cnf" --datadir="$datadir" --socket="$socketfile" 
        --pid-file="$mypidfile" 
        --basedir="$basedir" --user=mysql >/dev/null &
    safe_pid=$!
    # Spin for a maximum of N seconds waiting for the server to come up;
    # exit the loop immediately if mysqld_safe process disappears.
    # Rather than assuming we know a valid username, accept an "access
    # denied" response as meaning the server is functioning.
    ret=0
    TIMEOUT="$STARTTIMEOUT"
    while [ $TIMEOUT -gt 0 ]; do
        RESPONSE=$(/usr/bin/mysqladmin --no-defaults --socket="$adminsocket" --user=UNKNOWN_MYSQL_USER ping 2>&1) && break
        echo "$RESPONSE" | grep -q "Access denied for user" && break
        if ! /bin/kill -0 $safe_pid 2>/dev/null; then
        echo "MySQL Daemon failed to start."
        ret=1
        break
        fi
        sleep 1
        let TIMEOUT=${TIMEOUT}-1
    done
    if [ $TIMEOUT -eq 0 ]; then
        echo "Timeout error occurred trying to start MySQL Daemon."
        ret=1
    fi
    if [ $ret -eq 0 ]; then
        action $"Starting $prog: " /bin/true
        touch $lockfile
    else
        action $"Starting $prog: " /bin/false
    fi
    fi
    return $ret
}

stop(){
    if [ ! -f "$mypidfile" ]; then
        # not running; per LSB standards this is "ok"
        action $"Stopping $prog: " /bin/true
        return 0
    fi
    MYSQLPID=`cat "$mypidfile"`
    if [ -n "$MYSQLPID" ]; then
        /bin/kill "$MYSQLPID" >/dev/null 2>&1
        ret=$?
        if [ $ret -eq 0 ]; then
        TIMEOUT="$STOPTIMEOUT"
        while [ $TIMEOUT -gt 0 ]; do
            /bin/kill -0 "$MYSQLPID" >/dev/null 2>&1 || break
            sleep 1
            let TIMEOUT=${TIMEOUT}-1
        done
        if [ $TIMEOUT -eq 0 ]; then
            echo "Timeout error occurred trying to stop MySQL Daemon."
            ret=1
            action $"Stopping $prog: " /bin/false
        else
            rm -f $lockfile
            rm -f "$socketfile"
            action $"Stopping $prog: " /bin/true
        fi
        else
        action $"Stopping $prog: " /bin/false
        fi
    else
        # failed to read pidfile, probably insufficient permissions
        action $"Stopping $prog: " /bin/false
        ret=4
    fi
    return $ret
}

restart(){
    stop
    start
}

condrestart(){
    [ -e $lockfile ] && restart || :
}


# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status -p "$mypidfile" $prog
    ;;
  restart)
    restart
    ;;
  condrestart|try-restart)
    condrestart
    ;;
  reload)
    exit 3
    ;;
  force-reload)
    restart
    ;;
  *)
    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
    exit 2
esac

exit $?

应用下边包车型大巴吩咐管理多个实例:

service mysqld3306 {start|stop|status|restart}
service mysqld3307 {start|stop|status|restart}

首先次开发银行恐怕会停业,也大概会警告和log相关的项,那是不奇怪的,之后都会寻常。

贰.一 mysql多实例配置进程

本文介绍第两种方法,并行使rpm包安装的mysql完毕多实例。再一次印证,无论使用何种措施安装mysql,都得以兑现多实例,其实看驾驭下边配置的进度就通晓了。

创制并设置datadir,并早先化、分别提供配置文件。

shell> mkdir -p /mydata/{3306,3307}/data
shell> chown -R mysql.mysql /mydata/{3306,3307}/data
shell> mysql_install_db --datadir=/mydata/3306/data --user=mysql
shell> mysql_install_db --datadir=/mydata/3307/data --user=mysql
shell> cp /etc/my.cnf /mydata/3306/my.cnf
shell> cp /etc/my.cnf /mydata/3307/my.cnf

假若是安装mysql 5.7的多实例,则早先化时选取如下命令替换上面的mysql_install_db

shell> mysqld --initialize-insecure --datadir=/mydata/3306/data --user=mysql
shell> mysqld --initialize-insecure --datadir=/mydata/3307/data --user=mysql

分级修改四个布局文件。

#以下是3306实例的配置文件要修改的部分。
shell> vim /mydata/3306/my.cnf
[mysqld]
port=3306
datadir=/mydata/3306/data
socket=/mydata/3306/data/mysql.sock
server_id=1
[mysqld_safe]
log-error=/mydata/3306/data/mysqld.log
pid-file=/mydata/3306/data/mysqld.pid

#以下是3307实例的配置文件要修改部分。
shell> vim /mydata/3307/my.cnf
[mysqld]
port=3307
datadir=/mydata/3307/data
socket=/mydata/3307/data/mysql.sock
server_id=2
[mysqld_safe]
log-error=/mydata/3307/data/mysqld.log
pid-file=/mydata/3307/data/mysqld.pid
[root@linuxprobe ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.6.26-log MySQL Community Server (GPL)
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> flush tables with read lock; # 锁表
Query OK, 0 rows affected (0.01 sec)
mysql> show master status; #记住file的数值和position的值
 ------------------ ---------- -------------- ------------------ ------------------- 
| File  | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
 ------------------ ---------- -------------- ------------------ ------------------- 
| mysql-bin.000001 | 400 |  |   |   |
 ------------------ ---------- -------------- ------------------ ------------------- 
1 row in set (0.00 sec)
mysql> exit
Bye
#
[root@linuxprobe ~]# mysqldump -u root -p --all-databases --lock-all-tables --events > mysql_dump.sql # 备份数据库
Enter password: 
[root@linuxprobe ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 5
Server version: 5.6.26-log MySQL Community Server (GPL)

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> unlock tables; # 解锁
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
[root@linuxprobe ~]# scp mysql_dump.sql vdevops.org@/tmp/
cp: cannot create regular file ‘vdevops.org@/tmp/': No such file or directory
[root@linuxprobe ~]# scp mysql_dump.sql vdevops.org:/tmp/
The authenticity of host 'vdevops.org (10.1.1.56)' can't be established.
ECDSA key fingerprint is f8:d2:55:54:8f:e8:43:e0:ee:aa:d6:8d:53:8c:8e:85.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'vdevops.org' (ECDSA) to the list of known hosts.
mysql_dump.sql 

二.3 提供systemd服务管理脚本

  • 以下是330陆实例的军管脚本/usr/lib/systemd/system/mysqld3306.service。
  • 鉴于自家的言传身教中mysql是采取rpm安装,所以mysql的basedir为/usr,借使是编写翻译安装或通用二进制安装,则对应修改上面脚本中的basedir变量。
  • 是因为rpm包安装在centos 7上,已经未有mysqld_safe指令,由此选拔mysqld来启动mysql实例。
  • 将此管理脚本复制为/usr/lib/systemd/system/mysqld330七.service,再将其内的3306改变为3307就能够作为3307实例的劳动管理脚本。
  • 此脚本不会开首化mysql(小编把那有的代码删了)创造实例,所以运转服务前务必先开端化好相应的mysql实例。
  • 下边包车型大巴脚本就可以作为多实例服务管理脚本,也能够视作单实例服务管理脚本,只需将脚本名称改一改就可以。
  • mysql为systemd自带了多实例服务管理脚本/usr/lib/systemd/system/mysqld@.service。笔者尚未运用,但其设置格局能够借鉴下。
[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

Type=forking

PIDFile=/mydata/3306/data/mysqld.pid

# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0

# Execute pre and post scripts as root
PermissionsStartOnly=true

# Start main service
ExecStart=/usr/sbin/mysqld --defaults-file=/mydata/3306/my.cnf --basedir=/usr --daemonize $MYSQLD_OPTS
# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql

# Sets open_files_limit
LimitNOFILE = 5000

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false

下一场重载下systemd服务管理脚本。

systemctl daemon-reload

以往就能够利用下边包车型地铁命令管理三个实例:

systemctl {start|stop|status|restart} mysqld3306
systemctl {start|stop|status|restart} mysqld3307

二.二 提供sysV服务管理脚本

再各自提供服务处理脚本。

  • 以下是330陆实例的管理脚本/etc/init.d/mysqld330陆,内容退换自原有管理脚本/etc/init.d/mysqld。
  • 出于本人的言传身教中mysql是接纳rpm安装,所以mysql的basedir为/usr,若是是编写翻译安装或通用2进制安装,则对应修改上面脚本中的basedir变量。
  • mariadb安装和多实例配置,Yum编译安装MySQL。下边包车型客车datadir变量设置为/mydata/$port/data。请务必和方面包车型客车初叶化设置和配置文件中装置的如出一辙。
  • 将此管理脚本复制为/etc/init.d/mysqld330柒,再修改下port=330七就可以作为3307实例的劳务管理脚本。
  • 此脚本不会初阶化mysql(小编把那有的代码删了)创造实例,所以运营服务前务必先初步化好相应的mysql实例。
  • 上面包车型大巴本子就能够作为多实例服务管理脚本,也能够看作单实例服务处理脚本,只需将脚本名称改一改就可以。
#!/bin/sh
#
# mysqld    This shell script takes care of starting and stopping
#        the MySQL subsystem (mysqld).
#
# chkconfig: 345 64 36
# description:    MySQL database server.
# processname: mysqld

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

basedir=/usr
exec="$basedir/bin/mysqld_safe"
prog="mysqld"
port=3306
datadir="/mydata/$port/data"
socketfile="$datadir/mysql.sock"
errlogfile="$datadir/mysqld.log"
mypidfile="$datadir/mysqld.pid"
cnf="/mydata/$port/my.cnf"

# Set timeouts here so they can be overridden from /etc/sysconfig/mysqld
STARTTIMEOUT=120
STOPTIMEOUT=60

# Set in /etc/sysconfig/mysqld, will be passed to mysqld_safe
MYSQLD_OPTS=

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/$prog

case $socketfile in
    /*) adminsocket="$socketfile" ;;
     *) adminsocket="$datadir/$socketfile" ;;
esac

start(){
    [ -x $exec ] || exit 5
    # check to see if it's already running
    RESPONSE=$(/usr/bin/mysqladmin --no-defaults --socket="$adminsocket" --user=UNKNOWN_MYSQL_USER ping 2>&1)
    if [ $? = 0 ]; then
    # already running, do nothing
    action $"Starting $prog: " /bin/true
    ret=0
    elif echo "$RESPONSE" | grep -q "Access denied for user"
    then
    # already running, do nothing
    action $"Starting $prog: " /bin/true
    ret=0
    else
    # Now start service
    $exec $MYSQLD_OPTS --defaults-file="$cnf" --datadir="$datadir" --socket="$socketfile" 
        --pid-file="$mypidfile" 
        --basedir="$basedir" --user=mysql >/dev/null &
    safe_pid=$!
    # Spin for a maximum of N seconds waiting for the server to come up;
    # exit the loop immediately if mysqld_safe process disappears.
    # Rather than assuming we know a valid username, accept an "access
    # denied" response as meaning the server is functioning.
    ret=0
    TIMEOUT="$STARTTIMEOUT"
    while [ $TIMEOUT -gt 0 ]; do
        RESPONSE=$(/usr/bin/mysqladmin --no-defaults --socket="$adminsocket" --user=UNKNOWN_MYSQL_USER ping 2>&1) && break
        echo "$RESPONSE" | grep -q "Access denied for user" && break
        if ! /bin/kill -0 $safe_pid 2>/dev/null; then
        echo "MySQL Daemon failed to start."
        ret=1
        break
        fi
        sleep 1
        let TIMEOUT=${TIMEOUT}-1
    done
    if [ $TIMEOUT -eq 0 ]; then
        echo "Timeout error occurred trying to start MySQL Daemon."
        ret=1
    fi
    if [ $ret -eq 0 ]; then
        action $"Starting $prog: " /bin/true
        touch $lockfile
    else
        action $"Starting $prog: " /bin/false
    fi
    fi
    return $ret
}

stop(){
    if [ ! -f "$mypidfile" ]; then
        # not running; per LSB standards this is "ok"
        action $"Stopping $prog: " /bin/true
        return 0
    fi
    MYSQLPID=`cat "$mypidfile"`
    if [ -n "$MYSQLPID" ]; then
        /bin/kill "$MYSQLPID" >/dev/null 2>&1
        ret=$?
        if [ $ret -eq 0 ]; then
        TIMEOUT="$STOPTIMEOUT"
        while [ $TIMEOUT -gt 0 ]; do
            /bin/kill -0 "$MYSQLPID" >/dev/null 2>&1 || break
            sleep 1
            let TIMEOUT=${TIMEOUT}-1
        done
        if [ $TIMEOUT -eq 0 ]; then
            echo "Timeout error occurred trying to stop MySQL Daemon."
            ret=1
            action $"Stopping $prog: " /bin/false
        else
            rm -f $lockfile
            rm -f "$socketfile"
            action $"Stopping $prog: " /bin/true
        fi
        else
        action $"Stopping $prog: " /bin/false
        fi
    else
        # failed to read pidfile, probably insufficient permissions
        action $"Stopping $prog: " /bin/false
        ret=4
    fi
    return $ret
}

restart(){
    stop
    start
}

condrestart(){
    [ -e $lockfile ] && restart || :
}


# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status -p "$mypidfile" $prog
    ;;
  restart)
    restart
    ;;
  condrestart|try-restart)
    condrestart
    ;;
  reload)
    exit 3
    ;;
  force-reload)
    restart
    ;;
  *)
    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
    exit 2
esac

exit $?

接纳上面包车型地铁指令管理四个实例:

service mysqld3306 {start|stop|status|restart}
service mysqld3307 {start|stop|status|restart}

第③次运转大概会停业,也或许会警告和log相关的项,这是正规的,之后都会健康。

Slave 端:

3. mariadb安装

mariadb基本上算是mysql的另三个完结,绝大好多以及基础成效上和MySQL都毫无二致。具体到安装上,也基本完全等同。

在centos7上,直接yum install mysql-server将暗中同意安装mariadb,要是布置了mysql的yum源,需求钦赐"mysql-community-server"才代表安装mysql。

以下仅提供mariadb的各式财富下载地址,具体安装格局见前文对应mysql安装方式。个人建议,将mariadb的服务运维脚本阅读1回,和MySQL的做个比较。

mariadb的镜像站点:

[mariadb]
name=mariadb
baseurl=http://yum.mariadb.org/10.2.6/centos/6.6/$basearch/
#baseurl=http://yum.mariadb.org/10.2.6/centos/7.2/$basearch/
enabled=1
gpgcheck=0

mariadb各通用贰进制版:

mariadb各样贰进制版本:https://downloads.mariadb.org/mariadb/ releases/

mariadb 10.2.6 systemd版(centos7):http://ftp.hosteurope.de/mirror/archive.mariadb.org//mariadb-10.2.6/bintar-linux-systemd-x86_64/mariadb-10.2.6-linux-systemd-x86_64.tar.gz

mariadb安装和多实例配置,Yum编译安装MySQL。mariadb 10.2.6 非systemd版(centos6):http://ftp.hosteurope.de/mirror/archive.mariadb.org//mariadb-10.2.6/bintar-linux-x86_64/mariadb-10.2.6-linux-x86_64.tar.gz

mariadb源码包: http://ftp.hosteurope.de/mirror/archive.mariadb.org//mariadb-10.2.6/source/mariadb-10.2.6.tar.gz

二.3 提供systemd服务管理脚本

  • 以下是3306实例的管理脚本/usr/lib/systemd/system/mysqld330陆.service。
  • 由于自身的示范中mysql是行使rpm安装,所以mysql的basedir为/usr,如若是编写翻译安装或通用二进制安装,则对应修改下边脚本中的basedir变量。
  • 鉴于rpm包安装在centos 七上,已经未有mysqld_safe命令,由此使用mysqld来启动mysql实例。
  • 将此管理脚本复制为/usr/lib/systemd/system/mysqld3307.service,再将其内的330陆改变为3307就能够作为330七实例的服务管理脚本。
  • 此脚本不会初叶化mysql(笔者把那部分代码删了)创立实例,所以运行服务前务必先开端化好相应的mysql实例。
  • 下边包车型大巴台本就能够作为多实例服务管理脚本,也足以作为单实例服务管理脚本,只需将脚本名称改1改就能够。
  • mysql为systemd自带了多实例服务管理脚本/usr/lib/systemd/system/mysqld@.service。作者从没选用,但其安装方法能够借鉴下。
[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

Type=forking

PIDFile=/mydata/3306/data/mysqld.pid

# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0

# Execute pre and post scripts as root
PermissionsStartOnly=true

# Start main service
ExecStart=/usr/sbin/mysqld --defaults-file=/mydata/3306/my.cnf --basedir=/usr --daemonize $MYSQLD_OPTS
# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql

# Sets open_files_limit
LimitNOFILE = 5000

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false

接下来重载下systemd服务管理脚本。

systemctl daemon-reload

从此以后就足以行使下边包车型地铁通令管理三个实例:

systemctl {start|stop|status|restart} mysqld3306
systemctl {start|stop|status|restart} mysqld3307
[root@vdevops ~]# mysql -u root -p < /tmp/mysql_dump.sql
Enter password: 
[root@vdevops ~]# mysql -u root -p 
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.6.26-log MySQL Community Server (GPL)

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> change master to
 -> master_host='10.1.1.53', # master ip
 -> master_user='replica', # replication ID
 -> master_password='password', # replication passwd
 -> master_log_file='mysql-bin.000001', # bin-log number
 -> master_log_pos=400;  # position
Query OK, 0 rows affected, 2 warnings (0.03 sec)

mysql> start slave;
Query OK, 0 rows affected (0.01 sec)

mysql> show slave statusG
*************************** 1. row ***************************
  Slave_IO_State: Waiting for master to send event
   Master_Host: 10.1.1.53
   Master_User: replica
   Master_Port: 3306
  Connect_Retry: 60
  Master_Log_File: mysql-bin.000001
  Read_Master_Log_Pos: 475
  Relay_Log_File: mysqld-relay-bin.000002
  Relay_Log_Pos: 358
 Relay_Master_Log_File: mysql-bin.000001
  Slave_IO_Running: Yes
  Slave_SQL_Running: Yes
  Replicate_Do_DB: 
  Replicate_Ignore_DB: 
  Replicate_Do_Table: 
 Replicate_Ignore_Table: 
 Replicate_Wild_Do_Table: 
 Replicate_Wild_Ignore_Table: 
   Last_Errno: 0
   Last_Error: 
   Skip_Counter: 0
  Exec_Master_Log_Pos: 475
  Relay_Log_Space: 532
  Until_Condition: None
  Until_Log_File: 
  Until_Log_Pos: 0
  Master_SSL_Allowed: No
  Master_SSL_CA_File: 
  Master_SSL_CA_Path: 
  Master_SSL_Cert: 
  Master_SSL_Cipher: 
  Master_SSL_Key: 
 Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
  Last_IO_Errno: 0
  Last_IO_Error: 
  Last_SQL_Errno: 0
  Last_SQL_Error: 
 Replicate_Ignore_Server_Ids: 
  Master_Server_Id: 101
   Master_UUID: d47dddc3-9c70-11e6-8efb-000c29ffc05a
  Master_Info_File: /var/opt/rh/rh-mysql56/lib/mysql/master.info
   SQL_Delay: 0
  SQL_Remaining_Delay: NULL
 Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
  Master_Retry_Count: 86400
   Master_Bind: 
 Last_IO_Error_Timestamp: 
 Last_SQL_Error_Timestamp: 
  Master_SSL_Crl: 
  Master_SSL_Crlpath: 
  Retrieved_Gtid_Set: 
  Executed_Gtid_Set: 
  Auto_Position: 0
1 row in set (0.00 sec)

3. mariadb安装

mariadb基本上算是mysql的另二个贯彻,绝大很多以及基础成效上和MySQL都一样。具体到安装上,也基本完全平等。

在centos7上,直接yum install mysql-server将默许安装mariadb,若是布署了mysql的yum源,需求钦定"mysql-community-server"才表示安装mysql。

以下仅提供mariadb的种种财富下载地址,具体安装方式见前文对应mysql安装格局。个人提议,将mariadb的劳动运营脚本阅读二遍,和MySQL的做个相比较。

mariadb的镜像站点:

[mariadb]
name=mariadb
baseurl=http://yum.mariadb.org/10.2.6/centos/6.6/$basearch/
#baseurl=http://yum.mariadb.org/10.2.6/centos/7.2/$basearch/
enabled=1
gpgcheck=0

mariadb各通用2进制版:

mariadb各样贰进制版本:https://downloads.mariadb.org/mariadb/ releases/

mariadb 10.2.6 systemd版(centos7):http://ftp.hosteurope.de/mirror/archive.mariadb.org//mariadb-10.2.6/bintar-linux-systemd-x86_64/mariadb-10.2.6-linux-systemd-x86_64.tar.gz

mariadb 10.2.6 非systemd版(centos6):http://ftp.hosteurope.de/mirror/archive.mariadb.org//mariadb-10.2.6/bintar-linux-x86_64/mariadb-10.2.6-linux-x86_64.tar.gz

mariadb源码包: http://ftp.hosteurope.de/mirror/archive.mariadb.org//mariadb-10.2.6/source/mariadb-10.2.6.tar.gz

 

大好专项论题分享:mysql分歧版本安装教程 mysql五.柒各版本安装教程 mysql5.陆各版本安装教程

回来Linux种类小说大纲:http://www.cnblogs.com/f-ck-need-u/p/7048359.html

以上就是本文的全体内容,希望对我们的读书抱有支持,也愿意我们多多接济脚本之家。

回到数据库连串小说大纲:http://www.cnblogs.com/f-ck-need-u/p/7586194.html

你或然感兴趣的篇章:

  • Centos七下使用yum安装mysql数据库的详尽教程(加强版)
  • centos7 用rpm安装mysql详解
  • CentOS七.2虚拟机上设置MySQL ⑤.陆.32的学科
  • CentOS 七x6四下Apache MySQL(玛丽亚db) PHP5陆的安装教程详解
  • centos 七系统下编写翻译安装 mysql5.七学科
  • CentOS 7 安装 MySQL 5.6见面包车型地铁各个主题素材总计
  • centOS7安装MySQL数据库
  • Centos 6.四源码安装mysql-5.陆.2捌.tar.gz教程
  • linux下源码安装mysql5.6.20课程
  • CentOS 陆.四下编写翻译安装MySQL5.陆.1肆科目

转发请申明出处:http://www.cnblogs.com/f-ck-need-u/p/7590376.html

注:若你以为那篇文章尚可请点击右下角推荐,您的支撑能激起笔者更加大的编慕与著述热情,特别谢谢!

本文由澳门新萄京官方网站发布于数据库网络,转载请注明出处:mariadb安装和多实例配置,Yum编译安装MySQL

关键词: