• 【MySQL】MySQL多实例环境安装


    一 软件环境

    使用的软件分别为:

    • VirtualBox 5.2
    • MySQL 5.7.25

    二 版本选择

    版本选择策略为:

    • 官方社区版
    • 小版本20以上的版本

    三 软件安装

    1 删除之前版本

    [root@strong ~]# rpm -qa | grep mysql
    
    [root@strong ~]# rpm -qa | grep mariadb
    
    [root@strong ~]# yum remove mysql-server-5.1.71-1.el6.x86_64
    
    [root@strong ~]# find / -name *mysql*

    2 创建用户和组

    [root@strong ~]# groupadd mysql
    
    [root@strong ~]# useradd -r -g mysql -s /bin/false mysql

    3 解压安装文件

    [root@strong ~]# tar xvf /tmp/mysql-5.7.25-linux-glibc2.12-x86_64.tar
    
    [root@strong ~]# tar zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
    
    [root@strong ~]# mv mysql-5.7.25-linux-glibc2.12-x86_64 mysql
    
    [root@strong ~]# mv mysql /usr/local/
    
    [root@strong ~]# cd /usr/local/
    
    [root@strong local]# chown -R mysql.mysql mysql/

    4 创建数据库目录

    [root@strong ~]# mkdir -p /u01/data/mydb3306/
    
    [root@strong ~]# mkdir -p /u01/data/mydb3307/
    
    [root@strong ~]# chown -R mysql.mysql /u01/data/mydb3306/
    
    [root@strong ~]# chown -R mysql.mysql /u01/data/mydb3307/

    5 修改配置文件

    [root@strong ~]# vim /etc/my.cnf
    
    [mysqld_multi]
    
    mysqld=/usr/local/mysql/bin/mysqld_safe
    
    mysqladmin=/usr/local/mysql/bin/mysqladmin
    
    [mysqld3306]
    
    basedir=/usr/local/mysql
    
    datadir=/u01/data/mydb3306
    
    port=3306
    
    server_id=1
    
    socket=/u01/data/mydb3306/mysql3306.sock
    
    [mysqld3307]
    
    basedir=/usr/local/mysql
    
    datadir=/u01/data/mydb3307
    
    port=3307
    
    server_id=2
    
    socket=/u01/data/mydb3307/mysql3307.sock

    6 修改初始化参数文件

    [root@strong ~]# vim .bash_profile
    
    export PATH=$PATH:/usr/local/mysql/bin
    
    [root@strong ~]# . .bash_profile

    7 初始化数据库

    [root@strong ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/u01/data/mydb3306
    
    2019-04-14T12:46:51.822684Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    
    2019-04-14T12:46:52.774895Z 0 [Warning] InnoDB: New log files created, LSN=45790
    
    2019-04-14T12:46:52.995154Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    
    2019-04-14T12:46:53.242182Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 6114ce01-5eb3-11e9-8270-0800273a9619.
    
    2019-04-14T12:46:53.316235Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    
    2019-04-14T12:46:53.330096Z 1 [Note] A temporary password is generated for root@localhost: 0Y/tE)27c5gU
    
    [root@strong ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/u01/data/mydb3307
    
    2019-04-14T12:47:32.629460Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    
    2019-04-14T12:47:33.235757Z 0 [Warning] InnoDB: New log files created, LSN=45790
    
    2019-04-14T12:47:33.442469Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    
    2019-04-14T12:47:33.588142Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 79210c2e-5eb3-11e9-836e-0800273a9619.
    
    2019-04-14T12:47:33.655020Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    
    2019-04-14T12:47:33.656809Z 1 [Note] A temporary password is generated for root@localhost: 4bAtee4OEf;g

    8 查看数据库状态

    [root@strong ~]# mysqld_multi report
    
    Reporting MySQL servers
    
    MySQL server from group: mysqld3306 is not running
    
    MySQL server from group: mysqld3307 is not running

    9 启动数据库

    [root@strong ~]# mysqld_multi start 3306,3307

    10 查看数据库是否正常启动

    [root@strong ~]# mysqld_multi report
    
    Reporting MySQL servers
    
    MySQL server from group: mysqld3306 is running
    
    MySQL server from group: mysqld3307 is running
    
    [root@strong ~]# netstat -ntlp | grep mysql
    
    tcp 0 0 :::3307 :::* LISTEN 2080/mysqld
    
    tcp 0 0 :::3306 :::* LISTEN 2079/mysqld
    
    [root@strong ~]# ps -ef | grep mysql
    
    [root@strong ~]#
    
    [root@strong ~]# ll /u01/data/mydb3306/mysql3306.sock
    
    srwxrwxrwx. 1 mysql mysql 0 Apr 14 20:49 /u01/data/mydb3306/mysql3306.sock
    
    [root@strong ~]# ll /u01/data/mydb3307/mysql3307.sock
    
    srwxrwxrwx. 1 mysql mysql 0 Apr 14 20:49 /u01/data/mydb3307/mysql3307.sock

    11 修改Root密码

    [root@strong ~]# mysql -uroot -p'0Y/tE)27c5gU' -P 3306 -S /u01/data/mydb3306/mysql3306.sock
    
    mysql> set password=password('mysql');
    
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    [root@strong ~]# mysql -uroot -p'4bAtee4OEf;g' -P 3307 -S /u01/data/mydb3307/mysql3307.sock
    
    mysql> set password=password('mysql');

    12 关闭数据库

    [root@strong ~]# mysqladmin -uroot -pmysql -P 3306 -S /u01/data/mydb3306/mysql3306.sock shutdown
    
    [root@strong ~]# mysqladmin -uroot -pmysql -P 3307 -S /u01/data/mydb3307/mysql3307.sock shutdown

    至此,整个MySQL多实例环境安装完成。

  • 相关阅读:
    从留言簿开始,学习MonoRail MVC(三)
    从留言簿开始,学习MonoRail MVC(二)
    程序集版本最后一位使用SVN版本号的自动生成方法
    如何让.Net控件在设计时InitializeComponent()中不生成相关代码
    [收藏]Web Services and C# Enums
    从留言簿开始,学习MonoRail MVC(一)
    .Net控制USB设备相关内容
    .Net 2.0ListView控件在Windows 2000和Windows XP上的差异
    基于高德地图Windows Phone API 快速开发地图相关APP(二)
    android map api v2 示例 步骤及问题
  • 原文地址:https://www.cnblogs.com/alen-liu-sz/p/12975610.html
Copyright © 2020-2023  润新知