通过grant授权方式
此方法8.0版本不支持
grant 权限 on 库名.表名 to '用户名'@'IP' identified by '密码';
mysql> grant all privileges on *.* to 'root'@'localhost' identified by '000000';
Query OK, 0 rows affected (0.03 sec)
mysql> grant all privileges on *.* to 'root'@'%' identified by '000000';
Query OK, 0 rows affected (0.00 sec)
通过set password
Syntax:
SET PASSWORD [FOR user] = password_option
password_option: {
PASSWORD('auth_string')
| OLD_PASSWORD('auth_string')
| 'hash_string'
}
mysql> set password for root@'localhost' =password('000000');
Query OK, 0 rows affected (0.04 sec)
忘记密码情况
[root@server ~]# systemctl stop mysqld
[root@server ~]# mysqld_safe --skip-grant-tables --skip-networking
190801 04:33:20 mysqld_safe Logging to '/var/log/mysqld.log'.
190801 04:33:20 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[root@server ~]# mysql #可直接登陆
Wel