欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

CentOS 7.2 Yum编译安装MySQL 5.6

程序员文章站 2023-12-15 09:53:34
本文实例为大家分享centos 7.2 yum安装mysql5.6的方法,供大家参考,具体内容如下 配置centos sclo源 [3] 添加 centos s...

本文实例为大家分享centos 7.2 yum安装mysql5.6的方法,供大家参考,具体内容如下

配置centos sclo源

[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

yum安装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


开启防火墙

[root@linuxprobe ~]# firewall-cmd –add-service=mysql –permanent 
success 
[root@linuxprobe ~]# firewall-cmd –reload 
success

同样使用yum在vdevops.org上面安装mysql,安装步骤参考上面

mysql 主从

master端:linuxprobe

[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

开启防火墙

[root@linuxprobe ~]# firewall-cmd –add-service=mysql –permanent 
success 
[root@linuxprobe ~]# firewall-cmd –reload 
success

slave端:vdevops

[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

master端:备份数据库

[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 


slave 端:

[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)

精彩专题分享:mysql不同版本安装教程 mysql5.7各版本安装教程 mysql5.6各版本安装教程

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:

下一篇: