Linux环境下MySQL5.7连接Navicat

本文详细介绍了在CentOS7.9系统上安装并安全配置MySQL5.7.44,包括修改初始密码、设置强密码策略以及允许远程连接的权限设置,最后演示了如何通过Navicat连接数据库。
摘要由CSDN通过智能技术生成

操作系统:CentOS7.9

配置:4C/8G

数据库版本:MySQL5.7.44

本机IP:192.168.17.2

说明:如果已经安装完成MySQL直接从第二步设置权限开始,第一不非必须。

一.修改初始密码
方式一

日常使用的密码修改方式,推荐使用。

#先修改密码
[root@localhost ~]# grep password /var/log/mysqld.log 
2024-03-10T08:31:50.987694Z 1 [Note] A temporary password is generated for root@localhost: sUVwmT_q#1NG
[root@localhost ~]# mysql -uroot -p'sUVwmT_q#1NG'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.44

Copyright (c) 2000, 2023, 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.

#密码应该为:小写字母,大写字母,符号,数字,字符数>8
mysql> ALTER USER 'root'@'localhost'IDENTIFIED BY 'Linux2024312.';
Query OK, 0 rows affected (0.00 sec)

#刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
方式二

设置弱口令,设置简单密码,不能用于生产环境。

[root@localhost ~]# grep password /var/log/mysql.err 
2024-03-10T08:49:07.809029Z 1 [Note] A temporary password is generated for root@localhost: !stY5Ofyya4P
[root@localhost ~]# mysql -uroot -p'!stY5Ofyya4P'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.44-log

Copyright (c) 2000, 2023, 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> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

#设置弱口令
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

#可以修改简单的密码
mysql> alter user 'root'@'localhost' identified by '123123';
Query OK, 0 rows affected (5.00 sec)

#刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
二.设置权限
[root@localhost ~]# mysql -uroot -p'123123'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.44-log MySQL Community Server (GPL)

Copyright (c) 2000, 2023, 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;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
#用 % 能让任何 host 连接,也可以设置特定的 IP
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

#刷新权限
mysql> FLUSH PRIVILEGES;     
Query OK, 0 rows affected (0.00 sec)
三.Navicat连接数据库

主机IP写本机IP,端口没修改过默认3306,用户名root,密码是自己设置的

可以点测试连接,看看能否成功

让后点确认

到这里就结束了!

  • 10
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值