1.解压zip包到安装目录
比如我的安装目录是:D:\Program Files\MySQL
2.编写配置文件
在D:\Program Files\MySQL目录下创建my.ini文件
image.png
内容如下:
[mysqld]# 设置3306端口port=3306# 设置mysql的安装目录basedir=D:\Program Files\MySQL# 设置mysql数据库的数据的存放目录datadir=D:\Program Files\MySQL\Data# 允许最大连接数max_connections=200# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统max_connect_errors=10# 服务端使用的字符集默认为UTF8character-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=3306default-character-set=utf8
注意,里面的 basedir 是我本地的安装目录,datadir 是我数据库数据文件要存放的位置,各项配置需要根据自己的环境进行配置。
使用default_authentication_plugin=mysql_native_password是为了后续navicat可以远程连接
3.使用管理员身份打开CMD窗口初始化安装
注意,一定要使用管理员身份
然后cd到D:\Program Files\MySQL\bin目录下
执行
mysqld --initialize --console
成功之后输入如下:
D:\Program Files\MySQL\bin>mysqld --initialize --console2018-12-04T03:26:47.785247Z 0 [System] [MY-013169] [Server] D:\Program Files\MySQL\bin\mysqld.exe (mysqld 8.0.13) initializing of server in progress as process 77482018-12-04T03:26:47.922126Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.2018-12-04T03:27:05.431061Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: _nv04Hp%DXuc2018-12-04T03:27:19.755014Z 0 [System] [MY-013170] [Server] D:\Program Files\MySQL\bin\mysqld.exe (mysqld 8.0.13) initializing of server has completed
注意,里面有一句
A temporary password is generated for root@localhost: _nv04Hp%DXuc
这个_nv04Hp%DXuc就是mysql为我们生成的一个临时root密码,务必记住
如果忘记了,就把mysql目录删掉重头再来
4.安装mysql服务
mysqld --install mysql
这里的mysql可以改为你想要自定义的,比如你机器上有很好几个mysql,你可以起名为mysql8
安装成功后,输出是这样的:
D:\Program Files\MySQL\bin>mysqld --install mysql Service successfully installed.
5.启动mysql服务
直接执行
net start mysql
6.登录连接mysql
在命令行输入:
mysql -u root -p
然后会提示你输入密码
这里的密码就是第2步让你记住的密码
登录成功后输出如下
D:\Program Files\MySQL\bin>mysql -u root -p Enter password: ************ Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8Server version: 8.0.13Copyright (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.
可以执行下
show databases
检测下
7.修改root密码
连接进入后,直接输入下面语句,我这里是将默认密码设置为123456,你可以修改为自己想要定义的.
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
8.允许远程连接访问
执行
use mysql;
然后查看下当前连接允许情况
select host, user, authentication_string, plugin from user;
我这里的输出如下:
mysql> select host, user, authentication_string, plugin from user; +-----------+------------------+------------------------------------------------------------------------+-----------------------+| host | user | authentication_string | plugin | +-----------+------------------+------------------------------------------------------------------------+-----------------------+ | localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password || localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | | localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password || localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | mysql_native_password | +-----------+------------------+------------------------------------------------------------------------+-----------------------+ 4 rows in set (0.00 sec)
然后执行
CREATE USER 'root'@'%' IDENTIFIED BY 'root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;
这个时候再查看下权限,输出如下
mysql> select host, user, authentication_string, plugin from user; +-----------+------------------+------------------------------------------------------------------------+-----------------------+| host | user | authentication_string | plugin | +-----------+------------------+------------------------------------------------------------------------+-----------------------+ | % | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | mysql_native_password || localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | | localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password || localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | | localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | mysql_native_password |+-----------+------------------+------------------------------------------------------------------------+-----------------------+5 rows in set (0.00 sec)
作者:程序鱼
链接:https://www.jianshu.com/p/2f3d3001599c
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦