mysql 登录是报错误Access denied for user root using password: YES
参考: https://tableplus.com/blog/2018/10/how-to-create-a-superuser-in-mysql.html
------------------
How to create a superuser in MySQL?
This guide will walk you through the steps to create a new user in MySQL and make it a super user with root-like access to the databases.
1. First, you have to log in with the root user, which has the CREATE USER privilege
Run this command to create a new user with a password:
CREATE USER 'username'@'localhost' IDENTIFIED BY 'the_password';
At this point, the new user has no permission over the databases. The next thing to do is to grant privileges to the new user. There are several privileges a user can have:
- ALL PRIVILEGES - a full root access to the databases. If no database is specified, it has global access across the system.
- CREATE - create new tables or databases
- DROP - delete tables or databases
- DELETE - delete rows from tables
- INSERT - insert rows into tables
- SELECT - use the SELECT command to read through databases
- UPDATE - update table rows
- GRANT OPTION - grant or remove other users’ privileges
2. Make it a superuser
To make this new user a superuser, we have to provide it with full root access to everything in the database, which means to GRANT ALL PRIVILEGES:
GRANT ALL PRIVILEGES ON *.* TO 'user_name'@'localhost' WITH GRANT OPTION;
It’s done, the new user now has the root-like permission.
3. Then create another account for the same new username
CREATE USER 'username'@'%' IDENTIFIED BY 'the_password';
And grant full root access:
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' WITH GRANT OPTION;
Both 'username'@'localhost'
and 'username'@'%'
are superuser accounts with full privileges to do anything.
The 'username'@'localhost'
account can be used only when connecting from the local host. The 'username'@'%'
account uses the '%'
wildcard for the host part, so it can be used to connect from any host.
4. To double check the privileges given to the new user, run SHOW GRANTS
command:
SHOW GRANTS FOR username;
5. Finally, when everything is settled, reload all the privileges:
FLUSH PRIVILEGES;
And all the changes will take effect immediately.
New to TablePlus? It’s a modern, native tool with an elegant GUI that allows you to simultaneously manage multiple databases such as MySQL, PostgreSQL, SQLite, Microsoft SQL Server and more.
Not on Mac? Download TablePlus for Windows.
On Linux? Download TablePlus for Linux
Need a quick edit on the go? Download TablePlus for iOS.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
2015-09-01 CakePHP下使用paginator需要对多个字段排序的做法