1、创建账户
MySQL5.8:
grant all privileges on *.* to tst@% identified by '123456';
MySQL8.0:
create user 'tst'@'%' identified by '123456';
grant all privileges on *.* to 'tst'@'%' with grant option;
ALTER USER 'tst'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
ALTER USER 'tst'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
2、修改密码
方法1: 用SET PASSWORD命令
mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
方法2:用mysqladmin
mysqladmin -u root password "123456"
#如果root已经设置过密码,采用如下方法
mysqladmin -u root password oldpass "123456"
方法3: 用UPDATE直接编辑user表
mysql -u root
mysql> use mysql;
mysql> UPDATE user SET Password = PASSWORD('123456') WHERE user = 'root';
mysql> FLUSH PRIVILEGES;
在丢失root密码的时候,可以这样
mysqld_safe --skip-grant-tables&
mysql -u root mysql
mysql> UPDATE user SET password=PASSWORD("") WHERE user='root';
mysql> FLUSH PRIVILEGES;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> SET PASSWORD = PASSWORD('123456');
其中 “123456” 为你要设置的数据密码。
标签:PASSWORD,创建,MySQL,密码,SET,user,mysql,123456,root From: https://blog.csdn.net/yao_guai/article/details/139769520