Jun*_* Oh 161 mysql passwords macos root
我正在尝试更改MySql root密码.
我所做的就是下面.
mysqld_safe --skip-grantupdate user set password=password('1111') where user='root';并收到错误消息 - > ERROR 1054 (42S22): Unknown column 'password' in 'field list'.仅供我,我做到了use mysql;.所以我在用户表上选择了查询,发现密码列实际上不存在.
这很奇怪.原始用户表是否可能没有密码列?
如何更改不存在的密码?
谢谢你的回答:D
nod*_*ejh 515
在MySQL 5.7中,mysql.user表字段中的密码字段已被删除,现在字段名称为'authentication_string'.
首先选择数据库:
mysql>use mysql;
Run Code Online (Sandbox Code Playgroud)
然后显示表格:
mysql>show tables;
Run Code Online (Sandbox Code Playgroud)
你会找到用户表,现在让我们看看它的字段:
mysql> describe user;
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Reload_priv | enum('N','Y') | NO | | N | |
| Shutdown_priv | enum('N','Y') | NO | | N | |
| Process_priv | enum('N','Y') | NO | | N | |
| File_priv | enum('N','Y') | NO | | N | |
| Grant_priv | enum('N','Y') | NO | | N | |
| References_priv | enum('N','Y') | NO | | N | |
| Index_priv | enum('N','Y') | NO | | N | |
| Alter_priv | enum('N','Y') | NO | | N | |
| Show_db_priv | enum('N','Y') | NO | | N | |
| Super_priv | enum('N','Y') | NO | | N | |
| Create_tmp_table_priv | enum('N','Y') | NO | | N | |
| Lock_tables_priv | enum('N','Y') | NO | | N | |
| Execute_priv | enum('N','Y') | NO | | N | |
| Repl_slave_priv | enum('N','Y') | NO | | N | |
| Repl_client_priv | enum('N','Y') | NO | | N | |
| Create_view_priv | enum('N','Y') | NO | | N | |
| Show_view_priv | enum('N','Y') | NO | | N | |
| Create_routine_priv | enum('N','Y') | NO | | N | |
| Alter_routine_priv | enum('N','Y') | NO | | N | |
| Create_user_priv | enum('N','Y') | NO | | N | |
| Event_priv | enum('N','Y') | NO | | N | |
| Trigger_priv | enum('N','Y') | NO | | N | |
| Create_tablespace_priv | enum('N','Y') | NO | | N | |
| ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | |
| ssl_cipher | blob | NO | | NULL | |
| x509_issuer | blob | NO | | NULL | |
| x509_subject | blob | NO | | NULL | |
| max_questions | int(11) unsigned | NO | | 0 | |
| max_updates | int(11) unsigned | NO | | 0 | |
| max_connections | int(11) unsigned | NO | | 0 | |
| max_user_connections | int(11) unsigned | NO | | 0 | |
| plugin | char(64) | NO | | mysql_native_password | |
| authentication_string | text | YES | | NULL | |
| password_expired | enum('N','Y') | NO | | N | |
| password_last_changed | timestamp | YES | | NULL | |
| password_lifetime | smallint(5) unsigned | YES | | NULL | |
| account_locked | enum('N','Y') | NO | | N | |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
45 rows in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)
惊喜!没有名为'password'的字段,密码字段名为'authentication_string'.所以,就这样做:
update user set authentication_string=password('1111') where user='root';
Run Code Online (Sandbox Code Playgroud)
现在,一切都会好的.
与MySQL 5.6相比,变化非常广泛:MySQL 5.7中的新功能
小智 23
我遇到的一个陷阱是现在没有密码字段,它已被重命名为:
update user set password=PASSWORD("YOURPASSWORDHERE") where user='root';
现在应该是:
update user set authentication_string=password('YOURPASSWORDHERE') where user='root';
bl7*_*l79 18
如果您没有在安装时设置密码,则会发生此错误,在本例中是使用unix-socket插件的mysql.
但是如果从设置中删除插件链接(表mysql.user)还会出现其他问题.这不能解决问题并产生另一个问题.要修复已删除的链接并设置密码("PWD"),请执行以下操作:
1)--skip-grant-tables如上所述运行.
如果它不起作用,那么skip-grant-tables在部分[mysqld]中 添加字符串/etc/mysql/mysql.conf.d/mysqld.cnf.然后呢
sudo service mysql restart.
2)运行mysql -u root -p,然后(更改"PWD"):
update mysql.user
set authentication_string=PASSWORD("PWD"), plugin="mysql_native_password"
where User='root' and Host='localhost';
flush privileges;
quit
Run Code Online (Sandbox Code Playgroud)
然后sudo service mysql restart.检查:mysql -u root -p.
在restart从文件mysqld.cnf中删除该字符串之前,如果你在那里设置它.
O. *_*nes 15
使用该ALTER USER命令而不是尝试更新USER行.请记住,可能有多个"root"用户,因为用户实体也是由他们连接的机器限定的
https://dev.mysql.com/doc/refman/5.7/en/alter-user.html
例如.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-password'
ALTER USER 'root'@'*' IDENTIFIED BY 'new-password'
Run Code Online (Sandbox Code Playgroud)
小智 5
仅当我在执行此处提到的命令后“刷新”时,它才对我起作用。这是我使用的命令的完整列表:
以前的答案可能不适用于更高版本的 mysql。如果之前的答案不适合您,请尝试以下步骤:
1-单击 wamp 图标 > mysql > mysql 控制台
2-一一写入以下命令
use mysql;
update user set authentication_string=password('your_password') where user='root';
FLUSH PRIVILEGES;
quit
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
190154 次 |
| 最近记录: |