创建新的用户名和密码
create user username identified by password
给用户分配权限
GRANT privileges ON databasename.tablename TO 'username'@'host'
grant all privileges on *.* to 'username'@'localhost' identified by 'password'
删除权限
REVOKE ALL PRIVILEGES ON *.* FROM 'username'@'localhost';
分配指定库的权限
GRANT ALL PRIVILEGES ON database1.* TO 'username'@'localhost' IDENTIFIED BY 'password';
分配指定操作的权限
GRANT SELECT, UPDATE ON database1.* TO 'username'@'localhost' IDENTIFIED BY 'password';
刷新权限
FLUSH PRIVILEGES
删除用户
DROP USER username@localhost;
设置默认的编码
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示
character_set_server=utf8
init_connect='SET NAMES utf8'
重启mysql
systemctl restart mysqld
更新用户的密码
SET PASSWORD FOR 'username'@'localhost' = PASSWORD("123456");