目录

安装环境
<https://blog.csdn.net/huzhongxi/article/details/81988988#%E5%AE%89%E8%A3%85%E7%8E%AF%E5%A2%83>

下载zip安装包
<https://blog.csdn.net/huzhongxi/article/details/81988988#%E4%B8%8B%E8%BD%BDzip%E5%AE%89%E8%A3%85%E5%8C%85>

环境配置
<https://blog.csdn.net/huzhongxi/article/details/81988988#%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE>

解压zip包到安装目录
<https://blog.csdn.net/huzhongxi/article/details/81988988#%E8%A7%A3%E5%8E%8Bzip%E5%8C%85%E5%88%B0%E5%AE%89%E8%A3%85%E7%9B%AE%E5%BD%95>

配置环境变量
<https://blog.csdn.net/huzhongxi/article/details/81988988#%E9%85%8D%E7%BD%AE%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F>

配置初始化的my.ini文件
<https://blog.csdn.net/huzhongxi/article/details/81988988#%E9%85%8D%E7%BD%AE%E5%88%9D%E5%A7%8B%E5%8C%96%E7%9A%84my.ini%E6%96%87%E4%BB%B6>

安装
<https://blog.csdn.net/huzhongxi/article/details/81988988#%E5%AE%89%E8%A3%85>

初始化数据库
<https://blog.csdn.net/huzhongxi/article/details/81988988#%E5%88%9D%E5%A7%8B%E5%8C%96%E6%95%B0%E6%8D%AE%E5%BA%93>

安装服务
<https://blog.csdn.net/huzhongxi/article/details/81988988#%E5%AE%89%E8%A3%85%E6%9C%8D%E5%8A%A1>

更改密码
<https://blog.csdn.net/huzhongxi/article/details/81988988#%E6%9B%B4%E6%94%B9%E5%AF%86%E7%A0%81>

配置远程登陆
<https://blog.csdn.net/huzhongxi/article/details/81988988#%E9%85%8D%E7%BD%AE%E8%BF%9C%E7%A8%8B%E7%99%BB%E9%99%86>

安装环境

win10

下载zip安装包

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

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


环境配置

解压zip包到安装目录

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



配置环境变量



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

配置初始化的my.ini文件

我们发现解压后的目录并没有my.ini文件,没关系可以自行创建。在安装根目录下添加 my.ini(新建文本文件,将文件类型改为.ini),写入基本配置:
[mysqld] #设置端口号 port=3306 #设置mysql的安装目录 #切记此处一定要用双斜杠\\
basedir=C:\\software\\tools\\mysql-8.0.12-winx64 #设置mysql数据库的数据存放目录
datadir=C:\\software\\tools\\mysql-8.0.12-winx64\\data #允许最大连接数
max_connections=200 #允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统 max_connect_errors=10 #
服务端使用的字符集默认为UTF8 character-set-server=utf8 # 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB # 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password [mysql] # 设置mysql客户端默认字符集
default-character-set=utf8 [client] # 设置mysql客户端连接服务端时默认使用的端口 port=3306
default-character-set=utf8
放入根目录中。

安装

初始化数据库

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



在MySQL安装目录的 bin 目录下执行命令:
mysqld --initialize --console
执行完成后,会打印 root 用户的初始默认密码,比如:
C:\Windows\system32>cd C:\software\tools\mysql-8.0.12-winx64\bin
C:\software\tools\mysql-8.0.12-winx64\bin>mysqld --initialize --console
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 2018-08-23T13:56:23.403547Z
5 [Note] [MY-010454] [Server] A temporary password is generated for
root@localhost: 07+e+Cj.Us0P 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服务。
C:\software\tools\mysql-8.0.12-winx64\bin>net start mysql mysql 服务正在启动 . mysql
服务已经启动成功。


更改密码

在MySQL安装目录的 bin 目录下执行命令:
mysql -u root -p
这时候会提示输入密码,记住了上面安装时的初始密码,填入即可登录成功,进入MySQL命令模式。
C:\software\tools\mysql-8.0.12-winx64\bin>mysql -uroot -p Enter password:
************ Welcome to the MySQL monitor. Commands end with ; or \g. Your
MySQL connection id is 10 Server version: 8.0.12 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.10 sec) mysql> exit; Bye C:\software\tools\mysql-8.0.12-winx64\bin>mysql
-uroot -proot mysql: [Warning] Using a password on the command line interface
can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your
MySQL connection id is 11 Server version: 8.0.12 MySQL Community Server - GPL
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>
在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加密方式修改了)
#检查用户
mysql> select user, host, plugin, authentication_string from user;
+------------------+-----------+-----------------------+------------------------------------------------------------------------+
| user | host | plugin | authentication_string |
+------------------+-----------+-----------------------+------------------------------------------------------------------------+
| hadoop | % | mysql_native_password |
*B34D36DA2C3ADBCCB80926618B9507F5689964B6 | | mysql.infoschema | localhost |
caching_sha2_password |
$A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | |
mysql.session | localhost | caching_sha2_password |
$A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | |
mysql.sys | localhost | caching_sha2_password |
$A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | root
| localhost | mysql_native_password | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B
|
+------------------+-----------+-----------------------+------------------------------------------------------------------------+
授权远程数据库

#授权所有权限 
GRANT ALL PRIVILEGES ON *.* TO 'hadoop'@'%';
#授权基本的查询修改权限,按需求设置
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON *.* TO 'hadoop'@'%';
查看用户权限
show grants for 'hadoop'@'%'; mysql> show grants for 'hadoop'@'%';
+------------------------------------+ | Grants for hadoop@% |
+------------------------------------+ | GRANT USAGE ON *.* TO `hadoop`@`%` |
+------------------------------------+ 1 row in set (0.00 sec)
总结

好记性不如烂笔头。

 

 

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信