修改 /etc/my.cnf,在 [mysqld] 小节下添加一行:
skip-grant-tables=1
重启mysql服务:
service mysqld restart
修改root账号密码:
update user set authentication_string = password('xxx'), password_expired = 'N', password_last_changed = now() where user = 'root';
连接过程中出现:Host is not allowed to connect this mysql service;执行如下命令
update user set host = '%' where user ='root'
给不同的数据库分配不同的用户:
grant all privileges on db1.* to 'username1'@'%' identified by 'password1';
grant all privileges on db2.* to 'username2'@'%' identified by 'password2';