3、设置/修改密码
方式一:
1.登陆到mysql中,将密码修改为root
mysql> set password for root@localhost = password('root');
Query OK, 0 rows affected (0.00 sec)
2.退出mysql
mysql> exit;
Bye
3.再次登陆需要使用密码登陆
[root@server-mysql src]# mysql -u root -p
Enter password: root
方式二:
1.登陆到mysql中,切换到mysql库
mysql> use mysql;
2.直接更新user表
mysql> update user set password=password('root') where user='root' and host='localhost';
3.刷新权限表
mysql> flush privileges;
方式三: 使用navicat修改,需要使用navicat连接上这个数据库
image.png
image.png
4、修改远程连接权限
1.切换到mysql库
mysql> use mysql;
Database changed
2.查看用户和能连接的主机, 发现root用户只能在本机连接(host中地址都是代表本机),不能远程用navicat连接
mysql> select user, host from user where user = 'root';
+------+--------------+
| user | host |
+------+--------------+
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
| root | server-mysql |
+------+--------------+
4 rows in set (0.00 sec)
3.修改用户访问的地址
mysql> Grant all privileges on *.* to root@'%' identified by 'root' with grant option;
Query OK, 0 rows affected (0.00 sec)
说明:*.*指对数据的所有权限(增删改查), root指连接上来的用户名,
‘%’指所有外部ip地址都可以连接上来,如果要指定地址可以这样写 ‘100.100.100.100’,
identified by 后跟的是连接上来的密码
4.再次查看, 发现root用户多了一个主机地址(%)
mysql> select user, host from user where user = 'root';
+------+--------------+
| user | host |
+------+--------------+
| root | % |
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
| root | server-mysql |
+------+--------------+
5 rows in set (0.00 sec)
5.刷新一下权限表
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
6.开放端口
[root@server-mysql src]# firewall-cmd --add-port=3306/tcp --permanent
success
[root@server-mysql src]# firewall-cmd --reload
success
网友评论