代码改变世界

mysql初设密码及允许远程访问

2021-04-20 16:57  Tanwheey  阅读(187)  评论(0编辑  收藏  举报

1、设置密码:

#mysql

  >set password for root@localhost = password('123456');    //设置密码

或:

  > grant all privileges on *.* to root@"127.0.0.1" identified by "123456" WITH GRANT OPTION;//设置密码

  >FLUSH PRIVILEGES;//设置生效

2、查看所有账号授权

>use mysql;//选择库

#查看所有账号及权限,如有空密码账号建议删除

>select host,user,password from user;

 

>delete from user where USER='';  //删除空密码

>exit;

2、登录:

#mysql -h127.0.0.1 -u root -p

输入密码:123456

3、授权:

>grant all privileges on *.* to root@"localhost" identified by "123456" WITH GRANT OPTION;

>FLUSH PRIVILEGES;

>grant all privileges on *.* to root@"xxx.xxx.xxx.xxx" identified by "123456" WITH GRANT OPTION;

>FLUSH PRIVILEGES;

>grant all privileges on *.* to root@"%" identified by "123456" WITH GRANT OPTION;

>FLUSH PRIVILEGES;

>system clear;//同linux的clear命令

4、查看数据库端口号:

>show global variables like 'port';

 

或:

# find / -name 'my.cnf'                                                                                                                                   

# vi ***/mysql/etc/my.cnf

 5、远程连接:

#mysql -h该主机ip -uroot -p -P3358