zoukankan      html  css  js  c++  java
  • MySQL基本操作

     

    1.设置数据库密码

    #1.简单的设置方式
    [root@db01 ~]# mysqladmin -uroot password '123'
    Warning: Using a password on the command line interface can be insecure.
    
    #2.安全的设置方式
    [root@db02 ~]# mysqladmin -uroot password
    New password: 123
    Confirm new password: 123

    2.使用密码登录数据库

    #1.正确的登陆方式(不标准,不安全)
    [root@db01 ~]# mysql -uroot -p123
    [root@db01 ~]# mysql -u root -p123
    
    #2.正确的登陆方式(标准,安全)
    [root@db01 ~]# mysql -u root -p
    Enter password:
    
    #3.错误的登陆方式(会把密码当成数据库)
    [root@db01 ~]# mysql -u root -p 123
    Enter password: 
    ERROR 1049 (42000): Unknown database '123'
    
    for password options, the password value is optional:  If you use a -p or --password option and specify the password value, there must be no space between -p or --password= and the password following it.
    #如果使用-p或者--password参数,他们与密码之间不能有空格
    
    If you use a -p or --password option but do not specify the password value, the client program prompts you to enter the password. The password is not displayed as you enter it. This is more secure than giving the password on the command line. Other users on your system may be able to see a password specified on the command line by executing a command such as ps auxw. 
    #如果只写-p或--password参数什么都不接,意思是让你手动输入密码
    
    #4.登录数据库后直接进入库中
    [root@db01 ~]# mysql -u root -p mysql
    Enter password: 

    3.查询数据库用户

    mysql> select user,host from mysql.user;
    +------+-----------+
    | user | host      |
    +------+-----------+
    | root | 127.0.0.1 |
    | root | ::1       |
    |      | db01      |
    | root | db01      |
    |      | localhost |
    | root | localhost |
    +------+-----------+
    6 rows in set (0.00 sec)

    4.删除没有用的用户(优化)

    mysql> drop user root@'::1';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> drop user ''@'localhost';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> drop user ''@'db01';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> delete from mysql.user where host='db01';
    Query OK, 1 row affected (0.00 sec)
    
    mysql> select user,host from mysql.user;
    +------+-----------+
    | user | host      |
    +------+-----------+
    | root | 127.0.0.1 |
    | root | localhost |
    +------+-----------+
    2 rows in set (0.00 sec)
  • 相关阅读:
    DFS迷宫递归所有路径 新手入门
    【翻译】Ext JS最新技巧——2016-3-4
    Android进程通信之一:两种序列化方式
    Ext JS 6应用程序Build后出现“c is not a constructor return new c(a[0])”的处理
    简约才是王道? CardView 的使用
    经过一段的努力,终于成为CSDN博客专家,感谢大家支持
    ACM_Uppercase(水题)
    ACM_01背包
    2018年北京信息科技大学第十届程序设计竞赛暨ACM选拔赛-B-precise math function
    goj N皇后问题
  • 原文地址:https://www.cnblogs.com/chenlifan/p/13849122.html
Copyright © 2011-2022 走看看