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;