mysql默认root用户没有密码,输入mysql –u root 进入mysql
1、初始化root密码
进入mysql数据库
1 | mysql> update user set password = PASSWORD (‘123456’) where User = 'root' ; |
2、允许mysql远程访问,可以使用以下三种方式:
a、改表。
3 | mysql> update user set host = '%' where user = 'root' ; |
4 | mysql> select host, user from user ; |
b、授权。
例如,你想root使用123456从任何主机连接到mysql服务器。
1 | mysql> GRANT ALL PRIVILEGES ON *.* TO 'root' @ '%' IDENTIFIED BY '123456' WITH GRANT OPTION ; |
如果你想允许用户jack从ip为10.10.50.127的主机连接到mysql服务器,并使用654321作为密码
1 | mysql> GRANT ALL PRIVILEGES ON *.* TO 'jack' @’10.10.50.127’ IDENTIFIED BY '654321' WITH GRANT OPTION ; |
c:在安装mysql的机器上运行:
2 | d:/mysql/bin/>mysql -h localhost -u root |
4 | mysql> GRANT ALL PRIVILEGES ON *.* TO 'root' @ '%' WITH GRANT OPTION |