MySQL在windows下相关的安装和配置操作,多个MySQL的安装详细教程

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/m0_37520980/article/details/82178367

我的博客介绍了大部分安装教程

https://blog.csdn.net/m0_37520980/article/details/80353315

当一台计算机安装多个MySQL的时候就需要一些下面的配置

mysqld --install [服务名] //这里可以设置服务名

重新解释一下安装的操作各个含义 

D:\Program Files\mysql-8.0.11>cd bin     //切换到bin目录下

D:\Program Files\mysql-8.0.11\bin>mysqld --remove //我以前安装过mysql,先移除
Service successfully removed.

D:\Program Files\mysql-8.0.11\bin>mysqld --install    //安装mysql,注意这里都是两个小横线
Service successfully installed.
D:\Program Files\mysql-8.0.11\bin>mysqld --install mysql5.6//这里可以设置服务名
设置服务名在一个机器安装多个MySQL服务时可以用到,建议服务名全部用小写,否则服务无法启动


D:\Program Files\mysql-8.0.11\bin>mysqld --initialize --console    //注意这里会生成一个密码
//在mysql5.6版本时,此步骤不能要,否则服务无法启动,
2018-05-17T07:59:00.988023Z 0 [System] [MY-013169] [Server] D:\Program Files\mysql-8.0.11\bin\mysqld.exe (mysqld 8.0.11) initializing of server in progress as process 3556
2018-05-17T07:59:25.239288Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 3<?*Yfr3>gdw    //这里3<?*Yfr3>gdw就是随机生成的密码
2018-05-17T07:59:45.170784Z 0 [System] [MY-013170] [Server] D:\Program Files\mysql-8.0.11\bin\mysqld.exe (mysqld 8.0.11) initializing of server has completed

D:\Program Files\mysql-8.0.11\bin>net start mysql    //启动mysql服务
MySQL 服务正在启动 ..
MySQL 服务已经启动成功。

D:\Program Files\mysql-8.0.11\bin>mysql -uroot -p  //登录mysql

Enter password: ************  //密码就是上面的密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.11
Copyright (c) 2000, 2018, 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> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'; //修改密码
Query OK, 0 rows affected (0.18 sec)//修改密码成功
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.10 sec)
mysql>

在安装了mysql 8.0.11之后又安装了mysql 5.6,现在我们再装一个MySQL 5.7 

记录一下过程

首先去官网下载 ----> 解压  配置环境变量 ------> 然后新建data文件夹---->新建my.ini

注意修改一下端口 我的修改成如下的样子

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8

[mysqld]
#设置3308端口,由于以前使用了3306和3307了,现在使用3308
port = 3308

# 设置mysql的安装目录,根据自己目录修改
basedir=D:\Program Files\mysql-5.7.23

# 设置mysql数据库的数据的存放目录
datadir=D:\Program Files\mysql-5.7.23\data

# 允许最大连接数
max_connections=1000

# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8

# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
###下面的这些配置我没用####
#忘记密码时使用
#skip-grant-tables
#设置协议认证方式
#default_authentication_plugin=mysql_native_password

然后就是一通安装服务   初始化数据库

扫描二维码关注公众号,回复: 4748226 查看本文章
D:\Program Files\mysql-5.7.23\bin>net stop mysql5.6
mysql5.6 服务正在停止..
mysql5.6 服务已成功停止。

D:\Program Files\mysql-5.7.23\bin>mysqld --install mysql5.7
Service successfully installed.

D:\Program Files\mysql-5.7.23\bin>mysqld --initialize --console
2018-08-28T06:36:00.740573Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-28T06:36:01.095911Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-08-28T06:36:01.157061Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-08-28T06:36:01.240661Z 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: a141f86a-aa8c-11e8-8b4d-3c970ecc8cb1.
2018-08-28T06:36:01.245321Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-08-28T06:36:01.601113Z 1 [Note] A temporary password is generated for root@localhost: H?HaNyCfH0h4

D:\Program Files\mysql-5.7.23\bin>net start mysql5.7
mysql5.7 服务正在启动 .
mysql5.7 服务已经启动成功。


D:\Program Files\mysql-5.7.23\bin>mysql -h localhost -P3308 -uroot -p
Enter password: ************
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

发现无法连接!!!

找了一会原因,发现服务有问题

发现5.6和5.7的路径竟然是一样的,果断删除服务

D:\Program Files\mysql-5.7.23\bin>net stop mysql5.7
mysql5.7 服务正在停止.
mysql5.7 服务已成功停止。


D:\Program Files\mysql-5.7.23\bin>mysqld --remove mysql5.7
Service successfully removed.

修改环境变量

path中将5.7的环境变量移到前面,

然后以管理身份重新打开一个命令窗口!!!

安装服务

C:\windows\system32>D:

D:\>cd D:\Program Files\mysql-5.7.23\bin

D:\Program Files\mysql-5.7.23\bin>mysqld --install mysql5.7
Service successfully installed.

查看服务正常

删除5.7路径下data目录中的所有内容(不删除直接启动服务也是可以的)

C:\windows\system32>D:

D:\>cd D:\Program Files\mysql-5.7.23\bin

D:\Program Files\mysql-5.7.23\bin>mysqld --install mysql5.7
Service successfully installed.

//初始化数据库,如果没有删除data文件夹可以不用初始化,直接启动服务即可
D:\Program Files\mysql-5.7.23\bin>mysqld --initialize --console
2018-08-28T07:21:38.729028Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-28T07:21:39.039243Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-08-28T07:21:39.098293Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-08-28T07:21:39.171396Z 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: 013123c2-aa93-11e8-9acb-3c970ecc8cb1.
2018-08-28T07:21:39.174562Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-08-28T07:21:39.193724Z 1 [Note] A temporary password is generated for root@localhost: )bMStHuCw2QE

//启动服务
D:\Program Files\mysql-5.7.23\bin>net start mysql5.7
mysql5.7 服务正在启动 .
mysql5.7 服务已经启动成功。

//指定端口链接数据库
D:\Program Files\mysql-5.7.23\bin>mysql -h localhost -P3308 -uroot -p
Enter password: ************   //这里是密码,博客中解释过了,如果没有重新初始化就是上一个密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23

Copyright (c) 2000, 2018, 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> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

至此,数据库安装完成。

效果,三个版本的数据库都启动成功,各自占用不同的端口

猜你喜欢

转载自blog.csdn.net/m0_37520980/article/details/82178367
今日推荐