windows, 数据库

Windows Server 安装MySQL Server

1、安装mysql前必须先安装依赖 Microsoft Visual C++ 2019 Redistributable。

2、mysql 8.4 采用cachng_sha2_password进行用户的密码加密

mysql> show plugins;
+———————————-+———-+——————–+———+———+
| Name | Status | Type | Library | License |
+———————————-+———-+——————–+———+———+
| binlog | ACTIVE | STORAGE ENGINE | NULL | GPL |
| sha256_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| caching_sha2_password | ACTIVE | AUTHENTICATION | NULL | GPL |
……
| mysql_native_password | DISABLED| AUTHENTICATION | NULL | GPL |
+———————————-+———-+——————–+———+———+

部分第三方的mysql客户端不支持这个加密方式可以修改为mysql 8.0.4之前的myslq_native_password,修改方法如下:在:\ProgramData\MySQL\MySQL Server 8.4 下的my.ini文件中修改一下内容:

[mysqld]
mysql_native_password=on

然后重启mysql84服务,在开始菜单打开”MySQL 8.4 Command Line Client”即可打开数据库的命令行。

mysql> show plugins;
+———————————-+———-+——————–+———+———+
| Name | Status | Type | Library | License |
+———————————-+———-+——————–+———+———+
| binlog | ACTIVE | STORAGE ENGINE | NULL | GPL |
| sha256_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| caching_sha2_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| sha2_cache_cleaner | ACTIVE | AUDIT | NULL | GPL |
……
| mysql_native_password | ACTIVE | AUTHENTICATION | NULL | GPL |
+———————————-+———-+——————–+———+———+
48 rows in set (0.00 sec)

3、用户管理:

创建用户:
   create user 'pig'@'%' identified with mysql_native_password by 'password123';
修改密码:
   alter user 'pig'@'%' identified with mysql_native_password by 'password123';
        或者:
   SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');
用户授权:
   grant all on *.* to 'pig'@'%';
查看授权情况:
   show grants for 'pig'@'%' \G;
移除授权:
   revoke all on *.* from 'pig'@'%';

数据库的备份还原

备份:
  mysqldump -uroot -p --databases db1 db2 > /path/to/db_backup.sql;
--备份db1、db2数据库。
  myslqdump -uroot -p db1 tb1 tb2 > /path/to/db_backup.sql;
--备份db1中的tb1、tb2表。
备份所有数据库:
  mysqldump -uroot -p --all-database > /path/to/db_backup.sql;
还原数据库:
  mysql -uroot -p < /path/to/db_backup.sql;
--还原数据库可以不指定还原哪个数据库

4、重置密码

修改my.cnf或者my.ini文件:
在[mysqld]下增加一行:
skip-grant-tables=true
重启mysqld服务
此刻使用空密码即可登录数据库,然后有命令修改密码即可

Leave a Reply