大器晚成、MySQL数据库的法定网站:

  • https://www.oracle.com/
  • http://dev.mysql.com/doc/refman/5.7/en/linux-installation.html
  •      
     //分化版本的设置文书档案和下载可以在这里地找

正文介绍mysql种种安装情势(rpm/glibc通用二进制/源码编写翻译)以致多实例配置的不二秘技,没什么技艺,算是豆蔻梢头篇方法合并随笔。

正文目录:
1.
mysql单实例安装
  1.1
rpm安装mysql
  1.2
通用二进制包安装mysql
    1.2.1
起头化数据库
    1.2.2
安装后的典型化操作
  1.3
编写翻译安装
    1.3.1
编写翻译安装进程
    1.3.2
初始化
    1.3.3
规范化
    1.3.4
cmake编写翻译MySQL时的挑肥拣瘦表达
2.
mysql多实例配置
  2.1
mysql多实例配置进度
  2.2
提供sysV服务管理脚本
  2.3
提供systemd服务管理脚本
3.
mariadb安装

本文实例为大家分享CentOS 7.2
Yum安装mysql5.6的不二诀要,供我们参考,具体内容如下

生机勃勃.安装条件:

二、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. 正文的安装遭受为centos6.6和centos7.2,但超越50%地点都是centos6.6作为示范示例。
  2. 正文安装MySQL时,它们的运维地点为mysql,数据目录datadir为/mydata/data。
  3. pid文件路线设置为/mydata/data/mysql.pid或/mydata/data/`hostname`.pid。
  4. 是因为mariadb和mysql
    5各类并未太大的不等。由此仅详细显示mysql的装置。最后将简单提生机勃勃提mariadb。

  5. mysql单实例安装

本文介绍mysql种种安装形式(rpm/glibc通用二进制/源码编写翻译)以致多实例配置的点子,没什么技术,算是少年老成篇方法归拢作品。

配置CentOS SCLo源

系统:CentOS6.5×64

三、Yum的措施安装MySQL:

  • yum安装mysql 5.7
    的官方安装方式地址

1、下载安装包

  • *此地址为Mysql 8.0 的安装源此中包括MySQL
    5.7的源,可以在后面步骤矫正开放的宾馆:
     *

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=/c\SELINUX=disabled' /etc/selinux/config
查看SELinux状态:
[root@host-131 ~]# getenforce
Disabled

 3、卸载系统自带的数据库(Centos7自带的是maridb卡塔 尔(阿拉伯语:قطر‎

1.1 rpm包安装mysql

直接yum安装mysql-server就能够。但只顾两点:

(1).centos7上,yum暗许将安装mariadb。
(2).centos6上,yum暗中认可安装的本子比较老(5.1版),要安装mysql 5.6或mysql
5.7,可以从官方下载,也足以运用以下配置的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.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
  1. 本文的装置境遇为centos6.6和centos7.2,但大非常多地点都是centos6.6作为示范示例。
  2. 正文安装MySQL时,它们的运营地方为mysql,数据目录datadir为/mydata/data。
  3. pid文件路线设置为/mydata/data/mysql.pid或/mydata/data/`hostname`.pid。
  4. 是因为mariadb和mysql
    5各个并不曾太大的不等。因而仅详细展现mysql的设置。最终将轻松提大器晚成提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

Apache: httpd-2.4.10.tar.gz

可参考:【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蒙受计划*

  

1.2 通用二进制包安装mysql

通用二进制包相当于windows中的便携版软件,解压后有一点配置下就能够直接利用,不用安装。

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

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

里头文件中的glibc2.12表示的是Linux系统的glibc版本要比2.12新,还行ldd --version翻开glibc版本。在CentOS
6上glibc私下认可正是2.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就能够。但注意两点:

(1).centos7上,yum默许将安装mariadb。
(2).centos6上,yum私下认可安装的本子相比老(5.1版),要安装mysql 5.6或mysql
5.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开始化时提示该命令已经甩掉(5.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

Mysql: mysql-5.6.20-linux-glibc2.5-x86_64.tar.gz

1.2.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

1.2 通用二进制包安装mysql

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

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

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

里头文件中的glibc2.12象征的是Linux系统的glibc版本要比2.12新,能够行使ldd --version翻看glibc版本。在CentOS
6上glibc暗中同意便是2.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
# 安装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

Php: php-5.6.0.tar.gz

1.2.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

1.2.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

拉开防火墙

Apr: apr-1.5.1.tar.gz

1.3 编写翻译源码安装mysql

建议别天下本无事,尝试编译装MySQL,完全部都以心劳日拙的事。若是确实要编写翻译安装,把my.cnf、服务管理脚本、编写翻译选项等事关到运维文件路线的项有限支撑同等,比方pid文件、socket文件、datadir路线、log文件。并保证mysql涉及到的目录全体者和所属组都以mysql,比如暗许的pid路线/var/run/mysql/。

mysql源码包下载地址:

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

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

1.2.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

Apr-util: apr-util-1.5.3.tar.gz

1.3.1 编写翻译安装进度

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

选取以下命令安装mysql 5.6。

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.7。比上述多了最后叁个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。

1.3 编写翻译源码安装mysql

提议别天下本无事,尝试编写翻译装MySQL,完全部都是心劳日拙的事。倘使真的要编写翻译安装,把my.cnf、服务管理脚本、编写翻译选项等关联到运营文件路线的项保险同等,举例pid文件、socket文件、datadir路线、log文件。并保管mysql涉及到的目录全数者和所属组都以mysql,举例私下认可的pid路径/var/run/mysql/。

mysql源码包下载地址:

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

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

风华正茂引致用yum在vdevops.org上边安装mysql,安装步骤参谋上面

Libxml2: libxml2-2.9.1.tar.gz

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.3.1 编写翻译安装进度

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

使用以下命令安装mysql 5.6。

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.7。比上述多了最后四个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 主从

暗中认可安装路线大家联合设置到/usr/local下

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 5.7提出利用如下语句举行初叶化。

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

如果是centos7,则提供systemd风格的服务处理脚本,并认然并非要订正pid文件路线。

Master端:linuxprobe

二.Apache安装:

1.3.4 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

设置Apache以前先把所急需的开拓包安装上,使用yum –y install gcc gcc-c++
pcre pcre-devel python python-devel

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.16中才起首提供该选项

1.3.4 cmake编写翻译MySQL时的挑精拣肥表明

拉开防火墙

图片 1

Storage Engine Options

累积引擎是插件式的,可被静态编写翻译到MySQL服务中,也足以动态编译成模块,编写翻译成模块时索要运用INSTALL PLUGIN言语或然--plugin-load选取来启用。但一些插件是恒久的,无法钦赐是静态编写翻译照旧动态编写翻译。

InnoDB,MyISAM,ME奥迪Q5GE,MEMOKoleosY和CSV存储引擎总是默许静态编写翻译到MySQL服务中的,在编写翻译安装的时候无需显式钦点它们。

编写翻译存款和储蓄引擎的时候,使用-DWITH_enginename_STORAGE_ENGINE=1表示静态编译到MySQL。可选的斯特林发动机有:ARC生殖器疱疹E、BLACKHOLE、EXAMPLE、FEDERATED、PARTITION(分区扶助引擎)、PEMuranoFSCHEMA(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.16中才伊始提供该选项
[root@linuxprobe ~]# firewall-cmd –add-service=mysql –permanent 
success 
[root@linuxprobe ~]# firewall-cmd –reload 
success

安装Apache2.4所须求运用的apr版本要在1.4以上,而Centos6.5自带的Apr版本是1.39,所以要活动到apr.apache.net网址上下载相应版本,大家那边下载的是风靡的1.5.1版本,Apr-util是1.5.3本子,还索要libxml2软件,因为libxml2是三个C语言的解析器,所以大家设置Apache的时候需求运用,源码安装的时候系统识别不了Libxml2的装置路线,所以大家得以自行设置tar包,小编这里下载的是2.9.1版本的。使用rpm
–qa apr apr-util libxml2下令查看Centos6.5装置的版本:

Feature Options

  • -DDEFAULT_CHARSET=charset_name

安装私下认可字符集,默以为latin1。例如,binary,ascii,big5
,gb2312,gbk,latin1,latin2,latin5,latin7,utf8。

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

字符集的装置能够在MySQL服务运行的时候利用”–character_set_server”选项来内定。

  • -DDEFAULT_COLLATION=collation_name

安装暗许的排序准则。暗中同意排序法规为latin1_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.

Storage Engine Options

储存引擎是插件式的,可被静态编写翻译到MySQL服务中,也得以动态编写翻译成模块,编译成模块时索要运用INSTALL PLUGIN言语可能--plugin-load选料来启用。但有些插件是定点的,不能够钦点是静态编写翻译如故动态编写翻译。

InnoDB,MyISAM,ME普拉多GE,MEMO昂科雷Y和CSV存款和储蓄引擎总是暗中认可静态编写翻译到MySQL服务中的,在编写翻译安装的时候无需显式钦点它们。

编写翻译存款和储蓄引擎的时候,使用-DWITH_enginename_STORAGE_ENGINE=1意味着静态编写翻译到MySQL。可选的内燃机有:ARC梅毒E、BLACKHOLE、EXAMPLE、FEDERATED、PARTITION(分区接济引擎)、PECRUISERFSCHEMA(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

图片 2

2. 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只需安装二次,即差别实例使用相符安装程序。但各样实例使用单独的安插文件、服务处理脚本、datadir目录和socket,而且启动与停止mysqld服务时须要钦命套接字文件。

Feature Options

  • -DDEFAULT_CHARSET=charset_name

安装暗中同意字符集,暗许为latin1。举个例子,binary,ascii,big5
,gb2312,gbk,latin1,latin2,latin5,latin7,utf8。

在cmake/character_sets.cmake文件中的CHA福特ExplorerSETS_AVAILABLE定义了同意行使的字符集列表。

字符集的设置可以在MySQL服务运营的时候利用”–character_set_server”选项来钦定。

  • -DDEFAULT_COLLATION=collation_name

安装私下认可的排序法规。暗中认可排序准则为latin1_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.1 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

2. 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只需安装三次,即分化实例使用相近安装程序。但种种实例使用单独的安排文件、服务管理脚本、datadir目录和socket,何况启动和停止mysqld服务时必要钦赐套接字文件。

Master端:备份数据库

创建安装目录:

2.2 提供sysV服务处理脚本

再各自提供劳务管理脚本。

  • 以下是3306实例的军事拘留脚本/etc/init.d/mysqld3306,内容退换自原有管理脚本/etc/init.d/mysqld。
  • 鉴于自家的亲自去做中mysql是运用rpm安装,所以mysql的basedir为/usr,如果是编写翻译安装或通用二进制安装,则对应改革上边脚本中的basedir变量。
  • 上边包车型大巴datadir变量设置为/mydata/$port/data。请必须和地点的起头化设置和布署文件中安装的等同。
  • 将此管理脚本复制为/etc/init.d/mysqld3307,再修正下port=3307就可以作为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相关的项,那是健康的,之后都会平常。

2.1 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 

始建相对应安装包目录:使用mkdir
/usr/local/{apr,apr-util,libxml2,apache,php} –v

2.3 提供systemd服务处理脚本

  • 以下是3306实例的治本脚本/usr/lib/systemd/system/mysqld3306.service。
  • 鉴于本身的亲自去做中mysql是利用rpm安装,所以mysql的basedir为/usr,假设是编写翻译安装或通用二进制安装,则对应改良上面脚本中的basedir变量。
  • 是因为rpm包安装在centos
    7上,已经未有mysqld_safe一声令下,因而使用mysqld来启动mysql实例。
  • 将此管理脚本复制为/usr/lib/systemd/system/mysqld3307.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

2.2 提供sysV服务管理脚本

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

  • 以下是3306实例的军事关押脚本/etc/init.d/mysqld3306,内容改换自原有管理脚本/etc/init.d/mysqld。
  • 由于本身的示范中mysql是运用rpm安装,所以mysql的basedir为/usr,要是是编写翻译安装或通用二进制安装,则对应修正上面脚本中的basedir变量。
  • 上边包车型地铁datadir变量设置为/mydata/$port/data。请必需和下边包车型地铁伊始化设置和配备文件中装置的豆蔻梢头致。
  • 将此管理脚本复制为/etc/init.d/mysqld3307,再校订下port=3307就可以作为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

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各通用二进制版:

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

2.3 提供systemd服务管理脚本

  • 以下是3306实例的军事关押脚本/usr/lib/systemd/system/mysqld3306.service。
  • 鉴于本人的言传身教中mysql是选择rpm安装,所以mysql的basedir为/usr,假若是编写翻译安装或通用二进制安装,则对应更改下边脚本中的basedir变量。
  • 是因为rpm包安装在centos
    7上,已经未有mysqld_safe一声令下,由此接受mysqld来启动mysql实例。
  • 将此管理脚本复制为/usr/lib/systemd/system/mysqld3307.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
[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 status\G
*************************** 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)

安装Apr:

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各通用二进制版:

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分歧版本安装教程
mysql5.7各版本安装教程
mysql5.6各版本安装教程

Shell>tar xf apr-1.5.1.tar.gz

归来Linux连串文章大纲:http://www.cnblogs.com/f-ck-need-u/p/7048359.html

以上正是本文的全体内容,希望对大家的学习抱有利于,也意在大家多多照应脚本之家。

Shell>cd apr-1.5.1

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

你或然感兴趣的随笔:

  • Centos7下使用yum安装mysql数据库的亲力亲为教程(巩固版)
  • centos7 用rpm安装mysql详解
  • CentOS7.2设想机上安装MySQL
    5.6.32的教程
  • CentOS 7
    x64下Apache+MySQL(Mariadb)+PHP56的安装教程详细解释
  • centos 7系统下编写翻译安装
    mysql5.7学科
  • CentOS 7 安装 MySQL
    5.6遭逢的各类主题素材计算
  • centOS7安装MySQL数据库
  • Centos
    6.4源码安装mysql-5.6.28.tar.gz教程
  • linux下源码安装mysql5.6.20课程
  • CentOS
    6.4下编写翻译安装MySQL5.6.14科目

Shell>./configure –prefix=/usr/local/apr

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

Shell>make && make install

相关文章