mysql-8.0.12-winx64安装教程(安装包的教程)

目录

安装环境

下载zip安装包

环境配置

解压zip包到安装目录

配置环境变量

配置初始化的my.ini文件

安装

初始化数据库

安装服务

更改密码

配置远程登陆

 

安装环境

win10


下载zip安装包

下载地址:https://dev.mysql.com/downloads/file/?id=479669

进入页面,点击底部"No thanks, just start my download."。开始下载。
mysql下载


环境配置

解压zip包到安装目录

我的解压在C:\software\tools\mysql-8.0.12-winx64

mysql目录结构

配置环境变量

环境变量

其中MYSQL_HOME=C:\software\tools\mysql-8.0.12-winx64

配置初始化的my.ini文件

我们发现解压后的目录并没有my.ini文件,没关系可以自行创建。在安装根目录下添加 my.ini(新建文本文件,将文件类型改为.ini),写入基本配置:(你创建了这个新文件之后,里面会有一些生成的内容,在复制下面的内容之前,要把这部分内容删除掉。并对下面的内容中的一些路径进行修改调整)

 
  1. [mysqld]

  2. #设置端口号

  3. port=3306

  4.  
  5. #设置mysql的安装目录

  6. #切记此处一定要用双斜杠\\

  7. basedir=C:\\software\\tools\\mysql-8.0.12-winx64

  8.  
  9. #设置mysql数据库的数据存放目录

  10. datadir=C:\\software\\tools\\mysql-8.0.12-winx64\\data

  11.  
  12. #允许最大连接数

  13. max_connections=200

  14.  
  15. #允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统

  16. max_connect_errors=10

  17.  
  18. # 服务端使用的字符集默认为UTF8

  19. character-set-server=utf8

  20.  
  21. # 创建新表时将使用的默认存储引擎

  22. default-storage-engine=INNODB

  23.  
  24. # 默认使用“mysql_native_password”插件认证

  25. default_authentication_plugin=mysql_native_password

  26.  
  27. [mysql]

  28. # 设置mysql客户端默认字符集

  29. default-character-set=utf8

  30.  
  31. [client]

  32. # 设置mysql客户端连接服务端时默认使用的端口

  33. port=3306

  34. default-character-set=utf8

放入根目录中。

安装

初始化数据库

在安装时,必须以管理员身份运行cmd,否则在安装时会报错,会导致安装失败的情况。

以管理员身份运行cmd

在MySQL安装目录的 bin 目录下执行命令:

mysqld --initialize --console

执行完成后,会打印 root 用户的初始默认密码,比如:

 
  1. C:\Windows\system32>cd C:\software\tools\mysql-8.0.12-winx64\bin

  2.  
  3. C:\software\tools\mysql-8.0.12-winx64\bin>mysqld --initialize --console

  4. 2018-08-23T13:56:18.046640Z 0 [System] [MY-013169] [Server] C:\software\tools\mysql-8.0.12-winx64\bin\mysqld.exe (mysqld 8.0.12) initializing of server in progress as process 11180

  5. 2018-08-23T13:56:23.403547Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 07+e+Cj.Us0P

  6. 2018-08-23T13:56:25.952809Z 0 [System] [MY-013170] [Server] C:\software\tools\mysql-8.0.12-winx64\bin\mysqld.exe (mysqld 8.0.12) initializing of server has completed

 

其中,初始密码为:07+e+Cj.Us0P。

安装服务

在MySQL安装目录的 bin 目录下执行命令:

mysqld --install [服务名]

后面的服务名可以不写,默认的名字为 mysql。当然,如果你的电脑上需要安装多个MySQL服务,就可以用不同的名字区分了,比如 mysql5 和 mysql8。

安装完成之后,就可以通过命令net start mysql启动MySQL的服务了。通过命令net stop mysql停止服务。通过命令sc delete MYSQL/mysqld -remove卸载MYSQL服务。

 
  1. C:\software\tools\mysql-8.0.12-winx64\bin>net start mysql

  2. mysql 服务正在启动 .

  3. mysql 服务已经启动成功。

任务管理器

更改密码

在MySQL安装目录的 bin 目录下执行命令:

mysql -u root -p

这时候会提示输入密码,记住了上面安装时的初始密码,填入即可登录成功,进入MySQL命令模式。

 
  1.  
  2. C:\software\tools\mysql-8.0.12-winx64\bin>mysql -uroot -p

  3. Enter password: ************

  4. Welcome to the MySQL monitor. Commands end with ; or \g.

  5. Your MySQL connection id is 10

  6. Server version: 8.0.12

  7.  
  8. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

  9.  
  10. Oracle is a registered trademark of Oracle Corporation and/or its

  11. affiliates. Other names may be trademarks of their respective

  12. owners.

  13.  
  14. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  15.  
  16. mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'root';

  17. Query OK, 0 rows affected (0.10 sec)

  18.  
  19. mysql> exit;

  20. Bye

  21.  
  22. C:\software\tools\mysql-8.0.12-winx64\bin>mysql -uroot -proot

  23. mysql: [Warning] Using a password on the command line interface can be insecure.

  24. Welcome to the MySQL monitor. Commands end with ; or \g.

  25. Your MySQL connection id is 11

  26. Server version: 8.0.12 MySQL Community Server - GPL

  27.  
  28. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

  29.  
  30. Oracle is a registered trademark of Oracle Corporation and/or its

  31. affiliates. Other names may be trademarks of their respective

  32. owners.

  33.  
  34. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  35.  
  36. mysql>

在MySQL中执行命令:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';  

修改密码,注意命令尾的;一定要有 ; 这是mysql的语法。

配置远程登陆

管理员root的host是localhost,代表仅限localhost登录访问。如果要允许开放其他ip登录,则需要添加新的host。如果要允许所有ip访问,可以直接修改成“%”。

创建用户:

CREATE USER 'hadoop'@'%' IDENTIFIED WITH mysql_native_password BY 'hadoop';

#(需要注意:mysql8.0加密方式修改了)
#检查用户

 
  1. mysql> select user, host, plugin, authentication_string from user;

  2. +------------------+-----------+-----------------------+------------------------------------------------------------------------+

  3. | user | host | plugin | authentication_string |

  4. +------------------+-----------+-----------------------+------------------------------------------------------------------------+

  5. | hadoop | % | mysql_native_password | *B34D36DA2C3ADBCCB80926618B9507F5689964B6 |

  6. | mysql.infoschema | localhost | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |

  7. | mysql.session | localhost | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |

  8. | mysql.sys | localhost | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |

  9. | root | localhost | mysql_native_password | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

  10. +------------------+-----------+-----------------------+------------------------------------------------------------------------+

授权远程数据库

#授权所有权限 

GRANT ALL PRIVILEGES ON *.* TO 'hadoop'@'%';

#授权基本的查询修改权限,按需求设置

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON *.* TO 'hadoop'@'%';

查看用户权限

show grants for 'hadoop'@'%';
 
  1. mysql> show grants for 'hadoop'@'%';

  2. +------------------------------------+

  3. | Grants for hadoop@% |

  4. +------------------------------------+

  5. | GRANT USAGE ON *.* TO `hadoop`@`%` |

  6. +------------------------------------+

  7. 1 row in set (0.00 sec)

结束!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值