0%

MacOS中MySQL密码丢失处理

01.MySQL

修改 root 密码 不成功

1
2
3
4
5
6
7
8
9
Open & Edit /etc/my.cnf or /etc/mysql/my.cnf, depending on your distro.
Add skip-grant-tables under [mysqld]
Restart Mysql
You should be able to login to mysql now using the below command mysql -u root -p
Run mysql> flush privileges;
Set new password by ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
Go back to /etc/my.cnf and remove/comment skip-grant-tables
Restart Mysql
Now you will be able to login with the new password mysql -u root -p
1
2
3
4
5
6
7
8
9
10
11
12
mysql> drop user root@localhost;
Query OK, 0 rows affected (0.00 sec)

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

mysql> create user root@localhost identified by 'abc.123';
Query OK, 0 rows affected (0.02 sec)

grant all privileges on *.* to root@localhost;

flush privileges;

mac brew 重装 不成功

1
2
3
4
5
brew uninstall mysql --ignore-dependencies
sudo rm -rf /usr/local/Cellar/mysql
brew cleanup
sudo rm -rf /usr/local/var/mysql
brew install mysql

索引

创建索引

1
2
alter table t_zxg_hot_news_result add index
idx_hot_news_cnt (ftype,fcnt,ftime,fnews_id,fmsg_type);

删除索引

1
alter table t_zxg_hot_news_result drop index idx_hot_news_cnt ;

查询索引

1
2
3
4
5
6
7
8
9
10
11
show index from t_zxg_hot_news_result;
+-----------------------+------------+------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-----------------------+------------+------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| t_zxg_hot_news_result | 0 | PRIMARY | 1 | fid | A | 765715 | <null> | <null> | | BTREE | | |
| t_zxg_hot_news_result | 1 | idx_hot_news_cnt | 1 | ftype | A | 5 | <null> | <null> | | BTREE | | |
| t_zxg_hot_news_result | 1 | idx_hot_news_cnt | 2 | fcnt | A | 4072 | <null> | <null> | | BTREE | | |
| t_zxg_hot_news_result | 1 | idx_hot_news_cnt | 3 | ftime | A | 49236 | <null> | <null> | YES | BTREE | | |
| t_zxg_hot_news_result | 1 | idx_hot_news_cnt | 4 | fnews_id | A | 800020 | <null> | <null> | | BTREE | | |
| t_zxg_hot_news_result | 1 | idx_hot_news_cnt | 5 | fmsg_type | A | 792176 | <null> | <null> | | BTREE | | |
+-----------------------+------------+------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+