創(chuàng)建用戶并授權(quán)
創(chuàng)建用戶
CREATE USER 'custom'@'localhost' IDENTIFIED BY 'password';
MySQL 8.0 默認(rèn)身份驗(yàn)證插件為caching_sha2_password,導(dǎo)致很多使用mysql_native_password身份驗(yàn)證的舊客戶端無法建立連接
如果使用舊版本的navicat,則執(zhí)行下面的語句
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourPassword'; FLUSH PRIVILEGES;
授權(quán)
GRANT ALL ON bankaccount.* TO 'custom'@'localhost';
root密碼重置
在/etc/my.cnf文件中加入下面內(nèi)容
skip-grant-tables
重啟mysqld服務(wù)
systemctl restart mysqld
登錄mysql,不用輸入密碼,直接回車
# mysql -uroot mysql> use mysql mysql> select host, user, authentication_string, plugin from user;
#如果authentication_string自動(dòng)查詢出來有內(nèi)容,執(zhí)行下面命令清空
mysql> update user set authentication_string='' where user='root';
刪除/etc/my.cnf中skip-grant-tables字段,重啟mysqld服務(wù)
systemctl restart mysqld
登錄mysql(此時(shí)密碼為空,回車即可),修改密碼
# mysql -uroot -p mysql> alter user 'root'@'localhost' identified by 'MhSqls@123';
允許root遠(yuǎn)程登錄
登錄mysql執(zhí)行下面命令
create user 'root'@'%' identified by 'MhSqls@123'; grant all on *.* to 'root'@'%' with grant option; flush privileges;
設(shè)置密碼過期時(shí)間
設(shè)置90天過期
CREATE USER 'jeffrey'@'localhost' PASSWORD EXPIRE INTERVAL 90 DAY; ALTER USER 'jeffrey'@'localhost' PASSWORD EXPIRE INTERVAL 90 DAY;
設(shè)置永不過期
CREATE USER 'jeffrey'@'localhost' PASSWORD EXPIRE NEVER; ALTER USER 'jeffrey'@'localhost' PASSWORD EXPIRE NEVER;