1、登陆mysql数据库
mysql -u root -p
#查看数据库
mysql>
show databases;
+--------------------+
| Database
|
+--------------------+
| information_schema |
| mysql
|
+--------------------+
2 rows in set (0.00 sec)
#查看user表
mysql> use mysql;
Database
changed
mysql> select host,user,password from
user;
+--------------+------+-------------------------------------------+
|
host | user | password
|
+--------------+------+-------------------------------------------+
|
localhost | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
|
192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E
|
+--------------+------+-------------------------------------------+
2
rows in set (0.00
sec)
#可以看到在user表中已创建的root用户。host字段表示登录的主机,其值可以用IP,也可用主机名.
MySQL>GRANT
ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘mypassword‘ WITH GRANT OPTION
#予任何主机访问数据的权限
3、MySQL>FLUSH PRIVILEGES
#修改生效
mysql> select host,user,password from
user;
+-----------+------+-------------------------------------------+
|
host | user | password
|
+-----------+------+-------------------------------------------+
| %
| root | *D75CC763C5551A420D28A227AC294FADE26A2FF2 |
|
127.0.0.1 | root | *D75CC763C5551A420D28A227AC294FADE26A2FF2
|
+-----------+------+-------------------------------------------+
2 rows
in set (0.00 sec)
#在mysql控制台执行命令中的 ‘root‘@‘%‘ 可以这样理解:
root是用户名,%是主机名或IP地址,这里的%代表任意主机或IP地址,你也可替换成任意其它用户名或指定唯一的IP地址;‘MyPassword‘是给授权用户指定的登录数据库的密码;另外需要说明一点的是我这里的都是授权所有权限,可以指定部分权限。
4、MySQL>EXIT
#退出MySQL服务器
#注意防火墙排除3306端口
5,远程主机测试(navicat for mysql)
转载地址:http://bbs.77169.com/read-htm-tid-322108-keyword-mysql.html
原文地址:http://www.cnblogs.com/jayGold/p/3758495.html