1 、查看mysql中的用户和密码
首先应用root 超级用户登录 拥有对 mysql 库的读和写操作。
应用数据库
use mysql;
查询用户密码
select host,user,password from user;
给用户设置 密码 localhost 指定ip
set password for root@localhost=password(‘root’);
设置任何主机Ip 访问
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '111111' WITH GRANT OPTION;
flush privileges;
例子:使用以下授权语句,将授权指定的192.168.1.1 和192.168.1.2 的机器,使用用户名为root,密码为test123的用户访问
grant all privileges on *.* to 'root'@'192.168.1.1' identified by 'test123';
grant all privileges on *.* to 'root'@'192.168.1.2' identified by 'test123'
2 修改用户的用户名 密码:
更改密码
mysql -u root -p
Enter password:***
mysql>use mysql; 选择数据库
Database changed
mysql> UPDATE user SET password=PASSWORD("新密码") WHERE user='你的用户名';
mysql> FLUSH PRIVILEGES;
mysql> quit;
更改用户名:
mysql -u root -p
Enter password:***
mysql> use mysql; 选择数据库
Database changed
mysql> update user set user="新用户名" where user="root"; 将用户名为root的改为新用户名
mysql> flush privileges; 刷新权限
mysql> exit