1.修改配置文件
vi /etc/mysql/mysql.conf.d/mysqld.cnf
//在[mysqld]添加跳过登录
skip-grant-tables
2.重启mysql服务并进入mysql客户端
mysql
flush privileges;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
3.修改配置文件并重启mysql
vi /etc/mysql/mysql.conf.d/mysqld.cnf
//在[mysqld]注释跳过登录
#skip-grant-tables
数据库授权
//创建用户host表示访问主机,不限制访问可以用“%”代替主机
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
// *.* 表示所有库 dbname.table
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;