17.问题:在Win10电脑上如何安装两个不同版本的MySQL数据库?

解决方案:如下所示

第1步:下载MySQL5.7.26压缩包(win10 64位版的MySQL5.7),下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

第2步:进入mysql-5.7.26-winx64文件夹,将下载好的my.ini文件【请到QQ群搜索该文件并下载】拷贝到当前目录,进行修改端口号,端口号改为3307,basedir和datadir也要重新配一下,具体修改内容如下所示:

    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
    # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
    # *** default location during install, and will be replaced if you
    # *** upgrade to a newer version of MySQL.

    [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=C:\Professional development tools\MySQL5.7\mysql-5.7.26-winx64
     datadir=C:\Professional development tools\MySQL5.7\mysql-5.7.26-winx64\data
     port=3307
     max_connections=200
     character_set_server=utf8
    # 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 

    default-storage-engine=INNODB
    explicit_defaults_for_timestamp=true
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

    [mysql]
    default-character-set=utf8

第3步:进入mysql5.7的bin目录下,按住shift键并点击鼠标左键进入cmd命令模式

第4步:安装mysql服务,指定该mysql服务名为mysql2,并根据my.ini文件进行安装

    mysqld install mysql2 --default-file="C:\Professional development tools\MySQL5.7\mysql-5.7.26-winx64\my.ini"

第5步:使用快捷键window+R输入services.msc点击确定打开系统服务,其中mysql2服务相关路径后续步骤进行修改

第6步:初始化数据(mysql服务安装成功后,就需要初始化数据库了,否则是无法启动服务的)

在bin目录下执行命令mysqld --initialize

初始化成功后,命令行没有任何提示。但在mysql5.7文件夹中已自动生成了data目录

第7步:使用快捷键window+R输入regedit点击确定打开系统注册表,找到HKEYLOCALMACHINE\SYSTEM\CurrentControlSet\Services\mysql2,选中右边ImagePath并点击鼠标右键“修改”进行修改ImagePath参数,更正mysql2服务相关路径【C:\Professional development tools\MySQL5.7\mysql-5.7.26-winx64\bin\mysqld mysql2】

第8步:使用快捷键window+R输入services.msc点击确定打开系统服务检查mysql2服务相关路径

第9步:停掉MySQL8.0数据库服务(停止之前安装的其他版本mysql服务)

第10步:配置MySQL5.7的环境变量(如果不配,那么用cmd输入mysql -u root -p进不了数据库)

第11步:启动MySQL5.7数据库服务,并修改初始密码和设置本地连接

在bin目录下执行命令net start mysql2

或者直接在系统中启动

mysql2服务启动后,去data/xxx.err文件中找到临时密码,进行登录

    如我这次的临时登录密码为uyCBtUkL*4bQ
    在bin目录下执行命令mysql -P3307 -uroot -p

    修改密码set password for root@localhost=password('44720843');
    退出exit;
    重新登录并输入刚设置的新密码mysql -P3307 -uroot -p
    设置本地连接ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '44720843';

第12步:使用SQLyog进行连接MySQL5.7数据库

至此,所有步骤整理完毕~

祝你好运!


5/14/2019 5:48:44 PM 已解决!