Windows Server2019安装MySQL5.7.25的方法

将解压文件放置C盘
配置环境变量 Patch:C:\mysql-5.7.25-winx64\bin;
安装mysql
切换到bin目录 cd C:*\bin

1.mysqld --initialize --console 打印root用户的初始密码 (失败删除data文件重新执行)

root@localhost:后面的“rI5rvf5x5G,E”就是初始密码(不含首位空格)。在没有更改密码前,需要记住这个密码,后续登录需要用到

2.安装服务bin目录下执行

mysqld --install mysql

3.启动服务(进入控制台直接运行)

net start mysql启动

4.停止服务

net stop mysql

5.更改密码(bin目录下运行):先要启动服务

mysql -u root -p
输入root密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';

--root远程权限

grant all PRIVILEGES on test_db.* to 'root'@'%' identified by '设置的密码';

6.可以用 命令查看一下默认安装的数据库:

show databases;
use mysql;
show tables;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql>

看到默认初始化了mysql数据库,其中user表里面存储MySQL用户信息。我们可以看一下默认MySQL用户:

 select user,host,authentication_string from mysql.user;
mysql> select user,host,authentication_string from mysql.user;
+------------------+-----------+-------------------------------------------+
| user             | host      | authentication_string                     |
+------------------+-----------+-------------------------------------------+
| mysql.infoschema | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.session    | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys        | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| root             | localhost | *27C237A977F4F44D3F551F1A673BE14DFD232961 |
+------------------+-----------+-------------------------------------------+
4 rows in set (0.00 sec)

mysql>

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

创建用户:

CREATE USER 'username'@'%' IDENTIFIED WITH mysql_native_password BY 'password';

示例

CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456';
CREATE USER 'pig'@'192.168.1.101_' IDENDIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '123456';

(需要注意:mysql8.0加密方式修改了)

检查用户

select user, host, plugin, authentication_string from user\G;

授权远程数据库

授权所有权限

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

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

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

查看用户权限

show grants for 'xxh'@'%';

示例:

mysql> use mysql;
Database changed
mysql> CREATE USER 'xxh'@'%' IDENTIFIED WITH mysql_native_password BY 'xxh123!@#'; #创建用户(注意:mysql8.0加密方式修改了)
Query OK, 0 rows affected (0.07 sec)
mysql>

查看密码加密方式:

mysql> select user, host, plugin, authentication_string from user;
+------------------+-----------+-----------------------+-------------------------------------------+
| user             | host      | plugin                | authentication_string                     |
+------------------+-----------+-----------------------+-------------------------------------------+
| xxh              | %         | mysql_native_password | *70FD6FB4F675E08FF785A754755B5EBA6DA62851 |
| mysql.infoschema | localhost | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.session    | localhost | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys        | localhost | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| root             | localhost | mysql_native_password | *27C237A977F4F44D3F551F1A673BE14DFD232961 |
+------------------+-----------+-----------------------+-------------------------------------------+
5 rows in set (0.00 sec)

mysql>

另外,如果需要新增账户,或者本机以外的其他人访问MySQL则还需要设置内置账户的host,具体可以参考:MySQL创建用户与授权

登录MySQL

mysql> 键入命令mysql -uroot -p, 回车后提示你输入密码,输入12345,然后回车即可

到此这篇关于Windows Server2019安装MySQL5.7.25的文章就介绍到这了,更多相关Windows Server安装MySQL内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

你可能感兴趣的:(Windows Server2019安装MySQL5.7.25的方法)