一、修改用户登录密码:

mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> quit
Bye
[root@rhel204 ~]# mysqladmin -uroot -p password --修改用户密码
Enter password:
New password:
Confirm new password:

[root@rhel204 ~]# mysql -uroot -p --以新密码登录
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
……
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.10 sec)

二、开启用户远程登录权限
--加-h参数远程登录mysql数据库提示如下错误
C:\Users\Administrator>mysql -uroot -p -h192.168.1.204
Enter password: *****
ERROR 1130 (HY000): Host '192.168.1.123' is not allowed to connect to this MySQL server
错误分析:主机'192.168.1.123'不允许连接到mysql数据库(没权限)。

[root@rhel204 ~]# myslq -uroot -p --本地登录
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user,password,host from user; --查看用户信息,的确root账号只允许本地登录。
+------+-------------------------------------------+-------------+
| user | password | host |
+------+-------------------------------------------+-------------+
| root | *76C1B58DE0F08B3169E76CEDD6DD814B32A36F78 | localhost |
| root | *76C1B58DE0F08B3169E76CEDD6DD814B32A36F78 | rhel204.com |
| root | *76C1B58DE0F08B3169E76CEDD6DD814B32A36F78 | 127.0.0.1 |
| root | *76C1B58DE0F08B3169E76CEDD6DD814B32A36F78 | ::1 |
+------+-------------------------------------------+-------------+
4 rows in set (0.00 sec)

mysql> grant all privileges on *.* to root@'%' identified by 'rusky'; --授权
Query OK, 0 rows affected (0.03 sec)
或:grant all on db1.* to username1@'%'; --授权用户username1从任一客户端远程登录数据库db1,并允许对库db1做所有操作。
"%"表示任何主机都可以远程登录到该服务器上访问。
*.*表示所有库的所有对象。
如果要限制只有某台机器可以访问,将%换成相应的IP即可,如:
GRANT ALL PRIVILEGES ON *.* TO username2@‘192.168.1.123’; --可省略IDENTIFIED BY '密码';或with grant option;

mysql> flush privileges; --刷新权限
Query OK, 0 rows affected (0.04 sec)

C:\Users\Administrator>mysql -uroot -p -h192.168.1.204 --root账号远程登录
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or \g.
……
mysql>

三、创建用户时就限制用户的权限:

create user   'lxj'@'%'    identified  by '123123';

@后面参数指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost, 如果想让该用户可以从任意远程主机登陆,可以使用通配符%.

最新文章

  1. VS2015 自动添加头部注释
  2. sql 数据库 初级 个人学习总结(一)
  3. Linux Unix 环境变量设置实例
  4. xenserver xensource.log不断增长
  5. java基础知识回顾之---java StringBuffer类
  6. LeetCode 327. Count of Range Sum
  7. MFC对话框和属性表
  8. 使用LayoutInflater添加一个布局引用
  9. Mac OS X 启用超级用户 sudo -s 获得系统权限 Mac终端命令
  10. Java知多少(52)内置异常
  11. 【python基础】迭代器和生成器函数
  12. asp.net乱码问题
  13. html5闰年判断函数
  14. Docker之Swarm
  15. python-day97--django-ModelForm
  16. shell脚本实例-nginx日志分析
  17. CocoaPods的 安装 /卸载/升级
  18. linux IP 设置
  19. 数据挖掘分类算法之决策树(zz)
  20. Hibernate 中 load() 方法导致的 noSession 异常

热门文章

  1. java遍历泛型的方法
  2. POJ 3694 LCA
  3. Hacker(12)----个人计算机安全防护策略
  4. web并发模型
  5. Visual Studio 2013 Web开发、新增功能:“Browser Link”
  6. ScrollView 的使用(非原创)
  7. C++服务器设计(三):多线程模型设计
  8. codeforces 336D Vasily the Bear and Beautiful Strings(组合数学)
  9. getHibernateTemplate().find方法详解
  10. 优先队列(和fence repair完全一样)