windows上安装多个mysql

为了试验mysql主从配置,需要在本机上安装多个mysql,下面是安装步骤。

  1. 官网下载mysql的zip包,也就是所谓的绿色版。下载连接:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.26-winx64.zip。 下载完成后解压缩,放到两个目录,起两个不同的名字,不要冲突。 我的目录是:

    • D:\Software\mysql\mysql-5.7.26-master
    • D:\Software\mysql\mysql-5.7.26-slave
  2. 复制一份mysql.ini到安装目录下,修改文件路径和端口号。

    basedir = D:\Software\mysql\mysql-5.7.26-master
    datadir = D:\Software\mysql\mysql-5.7.26-master\data
    port = 33061
    

    完整的my.ini文件如下:

    [mysqld]
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M
    
    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin
    
    # These are commonly set, remove the # and set as required.
    basedir = D:\Software\mysql\mysql-5.7.26-master
    datadir = D:\Software\mysql\mysql-5.7.26-master\data
    port = 33061
    # server_id = .....
    
    
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M 
    
    sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
    
    character-set-server = utf8mb4
    
    performance_schema_max_table_instances = 600
    table_definition_cache = 400
    table_open_cache = 256
    
    [mysql]
    default-character-set = utf8mb4
    
    [client]
    default-character-set = utf8mb4
    
    default_authentication_plugin=mysql_native_password
    
  3. 进入D:\Software\mysql\mysql-5.7.26-master\bin 目录下,以管理员身份启动cmd窗口,执行命令

    D:\Software\mysql\mysql-5.7.26-slave\bin\mysqld --install mysql-1 --defaults-file=D:\Software\mysql\mysql-5.7.26-master\my.ini
    

    这样会生成一个服务,mysql-1是生成的服务名称。

  4. 执行初始化命令。

    D:\Software\mysql\mysql-5.7.26-slave\bin\mysqld --initialize --console
    

    之后控制台会打印以下内容。

     2019-06-25T08:53:57.998809Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
     2019-06-25T08:53:57.998920Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
     2019-06-25T08:53:59.083792Z 0 [Warning] InnoDB: New log files created, LSN=45790
     2019-06-25T08:53:59.139447Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
     2019-06-25T08:53:59.211139Z 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: c5a6de91-9726-11e9-a26d-10653064abae.
     2019-06-25T08:53:59.214443Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
     2019-06-25T08:53:59.223199Z 1 [Note] A temporary password is generated for root@localhost: Ihfiqeg6kS/z
    

    最后一行生成一个临时密码,可以用来第一次登录。

  5. 启动服务。

    net start mysql-1
    
  6. 到这里就可以使用navicat等工具登录mysql了。

    停止mysql服务命令:

    net stop mysql-1
    

    删除mysql服务命令:

    D:\Software\mysql\mysql-5.7.26-slave\bin\mysqld --remove mysql-1
    

    直接使用mysqld命令需要添加环境变量,把D:\Software\mysql\mysql-5.7.26-slave\bin\目录添加到path中。

  7. 安装第二个mysql步骤同上,需要修改几个地方。

    • my.ini中的basedirdatadir
    • my.ini中的端口号
    • install命令生成的mysql服务名称

你可能感兴趣的:(mysql,数据库安装,多个mysql,绿色版mysql)