CentOS 7 modify mysql 8 password and authorize remote access

CentOS 7 modify mysql 8 password and authorize remote access

One, modify the password

1. Start the mysql service

service mysqld start

2. View the initial password (no password is set)

grep 'temporary password' /var/log/mysqld.log

As shown in the figure, the

Insert picture description here


initial password:iz-jbue8/L<c

3. Log in with the initial password

mysql -u root -p

As shown

Insert picture description here

4. Change password

change Password

ALTER USER 'root'@'localhost' IDENTIFIED BY '密码';

Update

flush privileges;

drop out

exit

5. Restart the service

service mysqld restart

As shown

Insert picture description here

6. Re-login verification

mysql -u root -p

As shown

Insert picture description here

Second, authorize remote access permissions

1. View mysql version

SELECT @@VERSION;

As shown in the figure:

Insert picture description here

2. Authorize remote access

(1) mysql 8

#创建账户
create user 'root'@'%' identified by  '密码'

#赋予权限,with grant option这个选项表示该用户可以将自己拥有的权限授权给别人
grant all privileges on *.* to 'root'@'%' with grant option

#改密码&授权超用户,flush privileges 命令本质上的作用是将当前user和privilige表中的用户信息/权限设置从mysql库(MySQL数据库的内置库)中提取到内存里
flush privileges;

Reason analysis: The mysql version of version 8 separates creating accounts and granting permissions.

  • create Account: create user ‘用户名’@‘访问主机’ identified by ‘密码’;
  • grant 权限列表 on 数据库 to ‘用户名’@‘访问主机’ with grant option;Grant permissions: This option means that the user can authorize the permissions he owns to others

(2) Other versions:

grant all privileges on *.* to 'root'@'%' identified by  '密码' with grant option