Mysql root password initialization and allows remote access (Ⅱ)

mysql default root user has no password, enter mysql -u root mysql enter

1, initialize the root password

Enter the mysql database

1
mysql> update  user  set  password = PASSWORD (‘123456’) where  User = 'root' ;

2, mysql allow remote access, you can use the following three ways:

a, change the table.

1
2
3
4
mysql -u root –p
mysql>use mysql;
mysql> update  user  set  host = '%'  where  user  = 'root' ;
mysql> select  host, user  from  user ;

b, authorization.

For example, you want to root from any host using 123456 connection to mysql server.

1
mysql> GRANT  ALL  PRIVILEGES  ON  *.* TO  'root' @ '%'  IDENTIFIED BY  '123456'  WITH  GRANT  OPTION ;

If you want to allow users to connect to the host jack 10.10.50.127 mysql server and use 654321 as a password from ip

1
2
mysql> GRANT  ALL  PRIVILEGES  ON  *.* TO  'jack' @’10.10.50.127’ IDENTIFIED BY  '654321'  WITH  GRANT  OPTION ;
mysql>FLUSH RIVILEGES

c: mounting on the machine running the mysql:

1
2
3
4
5
6
7
8
//进入MySQL服务器
d:\mysql\bin\>mysql -h localhost -u root
//赋予任何主机访问数据的权限
mysql> GRANT  ALL  PRIVILEGES  ON  *.* TO  'root' @ '%'  WITH  GRANT  OPTION
//使修改生效
mysql>FLUSH PRIVILEGES
//退出MySQL服务器
mysql>EXIT
Published 18 original articles · won praise 10 · views 60000 +

Guess you like

Origin blog.csdn.net/qq_34146899/article/details/52557197