cmd 以管理员身份运行:
到mysql目录所在盘符:
C:\Windows\system32>d:
切换到MySQL bin目录:
D:\>cd D:\Program Files\mysql-8.0.21-winx64\bin
登录mysql:
D:\Program Files\mysql-8.0.21-winx64\bin>mysql -u root -p
Enter password: ***************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.24 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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.
出现以上字符,表示登录成功,切换到mysql数据库:
mysql> use mysql
Database changed
mysql> update user set authentication_string='123456' where user='root'and host='%';
Query OK, 1 row affected (0.09 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql>
以上update表示我已经给root授权访问,只不过开始密码一直为空
授权:
解决mysql中只能通过localhost访问不能通过ip访问的问题
原因是没开权限
SELECT * FROM USER WHERE USER='root';
grant all privileges on *.* to 'root'@'%' identified by '123456';
flush privileges;
1. 命令行进入mysql(假设root用户的密码也为root)
mysql –uroot –proot
2. 使用mysql数据库
use mysql;
3. 赋予权限
grant all privileges on *.* to ’root’@’%’ identified by ’root’;
其中*.*的意思是 所有库.所有表, 'root'@'%' identified by 'root'的前一个root是用户名,%是指所有访问ip,后一个root是指密码
这当然是一个糙汉子的赋权限方法,一个安静的女子应该将她写得优美而具体,比如:
grant all privileges on mdb.mtbl to ’beautiful’@’10.38.62.233’ identified by ’woman’;
4. 刷新权限(在不重启的情况下生效)
flush privileges;
听说实际实现方式是将user和privilige表里的东西扔进内存。
5. 重启mysql服务