当前位置:Gxlcms > 数据库问题 > Mac EI 10.11.3 MySQL5.7.11 .dmg 安装(便捷设置,密码重置,卸载)

Mac EI 10.11.3 MySQL5.7.11 .dmg 安装(便捷设置,密码重置,卸载)

时间:2021-07-01 10:21:17 帮助过:3人阅读

jacob@JacobdeMacBook-Pro:~$ sudo mysqld_safe --skip-grant-tables

重新打开一个终端 进入MySQL控制台

1
2
3
4
5
6
7
8
9
10
11
12
jacob@JacobdeMacBook-Pro:~$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.7-rc MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

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.

提示已经成功进入控制台

修改密码,sql语句

1
mysql> update mysql.user set password=password(‘123456‘) where user=‘root‘;

坑爹的地方来了,输入后报如下错误

1
ERROR 1054 (42S22): Unknown column ‘password‘ in ‘field list‘

神马情况,‘password‘列不存在,这个地方花了好多时间,原因其实很简单啊啊。

MySQL 5.7 版本中 user表中的密码字段列名称变了,从password变成了authentication_string
可以直接看一下user表中的字段

1
2
mysql> use mysql;
mysql> desc user;

部分字段如下

FieldTypeNullKeyDefaultExtra
Host char(60) NO PRI    
User char(16) NO PRI    
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  

最后用如下如下语句修改

1
2
3
4
5
6
mysql> update mysql.user set authentication_string=PASSWORD(‘123456‘) where user=‘root‘;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

修改成功,再次进入控制台

1
mysql> show databases;

这次可以进去了,但是随便执行一条语句依然报错啊

1
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement

按照提示再次设置密码

1
2
mysql> set password for root@localhost=password(‘12345‘);
Query OK, 0 rows affected, 1 warning (0.00 sec)

便捷设置

为方便使用 MySQL

cd /etc
sudo chmod +w bashrc
sudo vi bashrc
#在bashrc最后添加下面两行
alias mysql=‘/usr/local/mysql/bin/mysql‘
alias mysqladmin=‘/usr/local/mysql/bin/mysqladmin‘ 

Mac EI 10.11.3 MySQL5.7.11 .dmg 安装(便捷设置,密码重置,卸载)

标签:

人气教程排行