2、实现远程连接(授权法) 将host字段的值改为%就表示在任何客户端机器上能以root用户登录到mysql服务器,建议在开发时设为%。 update user set host = ’%’ where user = ’root’; 将权限改为ALL PRIVILEGES mysql> use mysql; Database changed mysql> grant all privileges on *.* to root@'%' identified by "root"; Query OK, 0 rows affected (0.00 sec) www.2cto.com mysql> select host,user,password from user; +--------------+------+-------------------------------------------+ | host | user | password | +--------------+------+-------------------------------------------+ | localhost | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E | | 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E | | % | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E | +--------------+------+-------------------------------------------+ 3 rows in set (0.00 sec) 这样机器就可以以用户名root密码root远程访问该机器上的MySql. 3、实现远程连接(改表法) use mysql; update user set host = '%' where user = 'root'; 这样在远端就可以通过root用户访问Mysql.
一、MySQL 连接本地数据库,用户名为“root”,密码“123”(注意:“-p”和“123” 之间不能有空格)
C:\>mysql -h localhost -u root -p123
二、MySQL 连接远程数据库(192.168.0.201),端口“3306”,用户名为“root”,密码“123”
C:\>mysql -h192.168.0.201 -P 3306 -u root -p123