mysql 安装步骤并设置远程连接

mysql 安装步骤并设置远程连接

前奏:
官网下载mysql
https://dev.mysql.com/downloads/mysql/.

1、创建一个配置文件my.ini,放到根目录
在这里插入图片描述

[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=D:\\java_work\\development\\mysql\\mysql-8.0.22-winx64
# 设置mysql数据库的数据的存放目录
datadir=D:\\java_work\\development\\mysql\\mysql-8.0.22-winx64\\data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。
max_connect_errors=10
# 服务端使用的字符集默认为utf8mb4
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
#mysql_native_password
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8mb4

1.1、管理员身份打开cmd,进入bin目录

cd D:\java_work\development\mysql\mysql-8.0.22-winx64\bin

在这里插入图片描述
2、安装

2.1执行命令

mysqld --initialize --console

如果遇到这个错误

传送:https://www.cnblogs.com/xianz666/p/12972224.html.

在这里插入图片描述

再次执行 mysqld --initialize --console 红框内是初始密码,进入后修改密码

在这里插入图片描述

2.2执行mysqld --install

mysqld --install

在这里插入图片描述
2.3开启服务,输入默认密码

net start mysql
mysql -u root -p

在这里插入图片描述
2.4登录成功后修改密码

 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

在这里插入图片描述
到这本地就可以连接了

如果安装错误想卸载:

##先关闭服务
net stop mysql 
##卸载
mysqld remove

3.设置远程连接

先查看一下用户信息:

SELECT host,user,authentication_string,plugin FROM user;

mysql> use mysql
Database changed
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)

mysql>

修改root,可以远程连接:

update user set host = ‘%’ where user = ‘root’;

mysql> use mysql
Database changed
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

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 |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)

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

mysql>

修改用户权限

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';

刷新权限

flush privileges;	
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值