【Mac + Mysql + Navicat Premium】之Navicat Premium如何连接Mysql数据库
参考文章:
因为我需要连接数据库工具,需要密码,所以下面介绍如何设置、修改密码实现Navicat Premium连接Mysql数据库
建议生产环境中mysql安装这完成后一定要运行一次mysql_secure_installation,在这里可以第一次设置密码,后续修改密码规则时可以多次修改密码,见下面:二、修改密码规则以及多次修改密码(但是,如果设置密码太简单低级会遇到密码策略问题,参考文章)
一、安全配置设置初始密码
启动mysql
mysql.server start
设置密码:
mysql_secure_installation
运行mysql_secure_installation会执行几个设置:
a)为root用户设置密码
b)删除匿名账号
c)取消root用户远程登录
d)删除test库和对test库的访问权限
e)刷新授权表使修改生效
代码如下:
Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: y ==》输入y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 ==》选择高中低密码,我选的0低级 Please set the password for root here. New password: ==》输入新密码 Re-enter new password: ==》再次输入新密码 Estimated strength of the password: 50 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y ==》安全只有50,输入y Password updated successfully! Reloading privilege tables.. … Success! By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n]<– 是否删除匿名用户,生产环境建议删除,所以直接回车 … Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n]<–是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止 … Success! By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n]<– 是否删除test数据库,直接回车 - Dropping test database… … Success! - Removing privileges on test database… … Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n]<– 是否重新加载权限表,直接回车 … Success! Cleaning up… All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL! [root@server1 ~]#
初始密码设置成功,验证一下,登陆mysql:
#登陆mysql mysql -u root -p
输入密码:xxxx
能进入就成功了!!!
二、修改密码规则以及可以多次修改密码
再返回到Navicat Premium中,
2059 - Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(../Frameworks/caching_sha2_password.so, 2): image not found
解决上面问题参考:《Navicat连接数据库MySQL报错2059》
是密码规则问题,解决问题如下:
#登陆mysql mysql -u root -p #输入密码 Enter password: xxx #修改加密规则 ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; #更新一下用户的密码 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; #刷新权限 FLUSH PRIVILEGES;
效果图:
但是,重新连接Navicat Premium时,还是报错
1045 - Access denied for user 'root'@'localhost' (using password: YES)
是因为,我上一步在更新密码中又把密码设置为“password”了,所以重新输入密码,再连接
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App