更改root密码(两种方法)
1. 命令行
--------------------------------------------------
# mysqladmin -u root password 密码
2. sql 语句
--------------------------------------------------
# mysql -u root -p
mysql>use mysql
mysql>update user set Password=password('new password') where user='root';
mysql>flush privileges;
允许远程连接与访问mysql
默认Mysql只允许本地登录,所以需要修改配置文件将地址绑定给注释掉:
# vim /etc/mysql/my.cnf
# Instead of skip-networking the defaultis now to listen only on
# localhost which is more compatible andisnot less secure.
#bind-address = 127.0.0.1---注释掉这一行就可以远程登录了
给用户远程访问授权(3种方式)
# mysql -u root -p
use mysql
赋予任何主机访问数据的权限
grant all privileges on *.* to root@"%" identified by "mysql"WITH grant option;
进行授权允许root用123密码从所有机器上可以登录本mysql服务器
grant allon *.* to root@"%" identified by "123";
允许root用123密码从192.168.100.254机器上可以登录本mysql服务器
grant allon *.* to root@192.168.100.254 identified by "123";
不用重启,直接更新
flush privileges;
mysql 5.7
SET PASSWORD = PASSWORD('123456'); 重设密码