关于安装两个MySQL的操作流程 <每个步骤都是经过反复多次的尝试总结而成>

本机已经安装了MySQL5.5,由于时间戳功能的限制,选择了再装一个MySQL5.7,没想到折腾了我一整晚的时间,从吃完晚饭一直到凌晨5点,一遍又一遍尝试,说出来都是泪-.-|,记录一下正确的操作流程,以备后患。

  1. 首先关闭原来MySQL5.5的服务(服务打开方式:鼠标右击任务栏,选择任务管理器,选择进程后面的服务,点击下方的打开服务),然后下载高版本的MySQL5.7,选择zip格式的解压免安装版。推荐使用镜像下载地址,原因不言而喻,官网下载那叫一个龟速。
    清华TUNA
    https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/
mysql-5.7.29-winx64.zip	        367.7 MiB	       2019-12-18 21:31
  1. 解压到自定义目录,并配置MySQL配置文件
    打开解压后的文件夹 E:\MySQL\mysql-5.7.29,在该文件下创建my.ini配置文件,使用Nodepad++工具编辑以下基本信息,转为ANSI编码格式保存配置文件my.ini(注意:端口号改为3307或者其它没占用的端口号)
[mysql] 
# 设置mysql客户端默认字符集
default-character-set=utf8 
[mysqld]
#设置3307端口
port = 3307 
# 设置mysql的安装目录
basedir=E:\\MySQL\\mysql-5.7.29
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB

建议直接复制粘贴,修改一下路径即可。

3.配置系统环境变量:

MySQL_HOME=“E:\MySQL\mysql-5.7.29”

PATH="%MySQL_HOME%\bin"

4.以管理员身份运行cmd命令行工具打开dos命令窗口
(搜索cmd选择以管理员身份运行),切换到bin所在目录,
执行命令(初始化):
mysqld --initialize --console

C:\WINDOWS\system32>e:

E:\>cd MySQL

E:\MySQL>cd mysql-5.7.29

E:\MySQL\mysql-5.7.29>cd bin

E:\MySQL\mysql-5.7.29\bin>mysqld --initialize --console 
2020-09-29T16:57:17.844932Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-09-29T16:57:19.898662Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-09-29T16:57:20.544557Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-09-29T16:57:20.795901Z 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: d6c99839-0274-11eb-8c0a-2c4d54396ffe.
2020-09-29T16:57:20.832918Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-09-29T16:57:22.661328Z 0 [Warning] CA certificate ca.pem is self signed.
2020-09-29T16:57:23.418681Z 1 [Note] A temporary password is generated for root@localhost: p0zgaVqAi7+d

执行结束会生成临时密码(p0zgaVqAi7+d)记录下来。

  1. 执行命令(安装命名):
E:\MySQL\mysql-5.7.29\bin>mysqld install mysql2 --default-file="E:\MySQL\mysql-5.7.29\my.ini"

5.打开注册表,找到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\mysql2,修改ImagePath参数,更正mysql2服务相关路径。

ImagePath的 数值数据 修改为:

"E:\MySQL\mysql-5.7.29\bin\mysqld" --defaults-file="E:\MySQL\mysql-5.7.29\my.ini" mysql2

6.dos命令窗口执行命令(启动mysql2):net start mysql2

E:\MySQL\mysql-5.7.29\bin>net start mysql2

The mysql2 service is starting.
The mysql2 service was started successfully.

7.执行命令(登录mysql2):

E:\MySQL\mysql-5.7.29\bin>mysql -P3307 -uroot -p
Enter password:*******

输入记录的临时密码。如果成功,那就恭喜你了!

8.执行命令(修改密码):

mysql>alter user 'root'@'localhost' identified by '123456';
mysql>flush privileges;

这只是理想状态,然而并没有这么容易,上面的临时密码会出现过期的状况。

临时密码过期解决办法:

  1. 重新以管理员身份进入dos命令窗口,切换到bin所在目录,执行命令(停止mysql服务):net stop mysql2
E:\MySQL\mysql-5.7.29\bin>net stop mysql2

The mysql2 service is stopping.
The mysql2 service was stopped successfully.

2.执行命令(无密码启动):mysqld --console --skip-grant-tables --shared-memory

E:\MySQL\mysql-5.7.29\bin>mysqld --console --skip-grant-tables --shared-memory
2020-09-29T17:19:27.163526Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-09-29T17:19:27.163600Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2020-09-29T17:19:27.164031Z 0 [Note] mysqld (mysqld 5.7.29) starting as process 9196 ...
2020-09-29T17:19:27.169855Z 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions
2020-09-29T17:19:27.171752Z 0 [Note] InnoDB: Uses event mutexes
2020-09-29T17:19:27.173811Z 0 [Note] InnoDB: _mm_lfence() and _mm_sfence() are used for memory barrier
2020-09-29T17:19:27.174269Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-09-29T17:19:27.175260Z 0 [Note] InnoDB: Number of pools: 1
2020-09-29T17:19:27.175801Z 0 [Note] InnoDB: Not using CPU crc32 instructions
2020-09-29T17:19:27.181707Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2020-09-29T17:19:27.187392Z 0 [Note] InnoDB: Completed initialization of buffer pool
2020-09-29T17:19:27.356181Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2020-09-29T17:19:28.121000Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2020-09-29T17:19:28.121982Z 0 [Note] InnoDB: Setting file '.\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2020-09-29T17:19:28.323731Z 0 [Note] InnoDB: File '.\ibtmp1' size is now 12 MB.
2020-09-29T17:19:28.326877Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2020-09-29T17:19:28.328183Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2020-09-29T17:19:28.329561Z 0 [Note] InnoDB: Waiting for purge to start
2020-09-29T17:19:28.381514Z 0 [Note] InnoDB: 5.7.29 started; log sequence number 2630312
2020-09-29T17:19:28.382452Z 0 [Note] Plugin 'FEDERATED' is disabled.
2020-09-29T17:19:28.383905Z 0 [Note] InnoDB: Loading buffer pool(s) from E:\MySQL\mysql-5.7.29\data\ib_buffer_pool
2020-09-29T17:19:28.621067Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2020-09-29T17:19:28.621598Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2020-09-29T17:19:28.625672Z 0 [Warning] CA certificate ca.pem is self signed.
2020-09-29T17:19:28.626657Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2020-09-29T17:19:28.627768Z 0 [Note] Server hostname (bind-address): '*'; port: 3307
2020-09-29T17:19:28.628996Z 0 [Note] IPv6 is available.
2020-09-29T17:19:28.629370Z 0 [Note]   - '::' resolves to '::';
2020-09-29T17:19:28.630390Z 0 [Note] Server socket created on IP: '::'.
2020-09-29T17:19:28.642942Z 0 [Note] Shared memory setting up listener
2020-09-29T17:19:28.983596Z 0 [Note] mysqld: ready for connections.
Version: '5.7.29'  socket: ''  port: 3307  MySQL Community Server (GPL)
2020-09-29T17:19:29.090640Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200930  1:19:29

3.使用工具Navicat创建连接:注意端口号改为3307,无需密码确定连接,进入名为"mysql"的数据库,打开名为"user"的表,找到user字段为root的记录行,修改authentication_string字段值为*7C9CB2A4F227FF764C10705941B03E2B1C378AF1,同时修改password_expired字段值为N,保存然后关闭连接退出。

4.关闭执行了无密码启动的dos命令窗口后,再次以管理员身份进入dos,切换到bin所在目录,执行命令(开启mysql服务):

E:\MySQL\mysql-5.7.29\bin>net start mysql2

5.执行命令(登录mysql2):

E:\MySQL\mysql-5.7.29\bin>mysql -P3307 -uroot -p
Enter password:*******

输入密码:Ei5PJ#K./fn-
登录成功!

6.执行命令(修改密码刷新):

mysql>alter user 'root'@'localhost' identified by '123456';
mysql>flush privileges;

修改自己的密码,退出,使用自己的密码重新登录,ok!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值