3 回答
TA贡献1772条经验 获得超5个赞
在MySQL 5.7中,删除了mysql.user表字段中的password字段,现在该字段名称为'authentication_string'。
首先选择数据库:
mysql>use mysql;
然后显示表格:
mysql>show tables;
您将找到用户表,现在让我们看一下它的字段:
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)
惊喜!没有名为“ password”的字段,而密码为“ authentication_string”。因此,只需执行以下操作:
update user set authentication_string=password('1111') where user='root';
现在,一切都会好的。
与MySQL 5.6相比,更改非常广泛:MySQL 5.7的新增功能
TA贡献1784条经验 获得超8个赞
我陷入的一个陷阱是现在没有密码字段,它已重命名为:
update user set password=PASSWORD("YOURPASSWORDHERE") where user='root';
现在应该是:
update user set authentication_string=password('YOURPASSWORDHERE') where user='root';
TA贡献1805条经验 获得超9个赞
如果您未在安装时设置密码,则会发生此错误,在本例中为使用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
然后sudo service mysql restart。检查:mysql -u root -p。
如果在restart文件mysqld.cnf中设置了该字符串,则将该字符串删除。
添加回答
举报