zoukankan      html  css  js  c++  java
  • Linux11.1 设置更改Mysql的root密码及连接mysql

    MySQL的root密码相关操作

      默认MySQL的root用户密码为空,可以直接登录

    [root@chy002 ~]# /usr/local/mysql/bin/mysql -uroot
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 1
    Server version: 5.6.35 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql>
    

      更改环境变量PATH,增加mysql绝对路径

    [root@chy002 ~]# echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
    [root@chy002 ~]# PATH=$PATH:/usr/local/mysql/bin/
    [root@chy002 ~]# mysql -uroot
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 2
    Server version: 5.6.35 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql> 
    

      设置MySQL的root用户密码

    [root@chy002 ~]# mysqladmin -uroot password 'chyuanliu'
    Warning: Using a password on the command line interface can be insecure.
    [root@chy002 ~]# mysql -uroot -pchyuanliu
    Warning: Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 6
    Server version: 5.6.35 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql>
    

      更改密码

    [root@chy002 ~]# mysqladmin -uroot -pchyuanliu password 'chyuanliu.1'
    Warning: Using a password on the command line interface can be insecure.
    

      mysql的root密码重置

    [root@chy002 ~]# vi /etc/my.cnf
    #增加一行配置
    skip-grant
    [root@chy002 ~]# /etc/init.d/mysqld restart
    Shutting down MySQL.. SUCCESS!
    Starting MySQL.. SUCCESS!
    [root@chy002 ~]# mysql -uroot
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 1
    Server version: 5.6.35 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql> usemysql;
    mysql> update user set password=password('liuchengyuan') where user='root';
    Query OK, 4 rows affected (0.00 sec)
    Rows matched: 4  Changed: 4  Warnings: 0
    
    mysql> Ctrl-C -- exit!
    Aborted
    [root@chy002 ~]# mysql -uroot -pliuchengyuan
    Warning: Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 3
    Server version: 5.6.35 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql>
    
    #再修改配置文件,去掉skip-grant,重启mysql

    连接mysql

      连接本机的mysql

    mysql -uroot -p123456  ==  mysql -uroot -p123456 -S/tmp/mysql.sock
    

      连接远程的mysql

    mysql -uroot -p123456 -h远程IP -P3306
    

      连接mysql后操作命令,多用于脚本

    [root@chy002 ~]# mysql -uroot -pliuchengyuan -e "show databases"
    

      

  • 相关阅读:
    SpringBoot集成Swagger2中不同环境开关配置
    mysql
    pip 命令汇总
    mysql 时间查询(当天、本周,本月,上一个月的数据)
    MYSQL 常用函数
    java8 array、list操作 汇【6】)- Java8 Lambda表达式增强版Comparator和排序
    解决pip安装超时的问题
    Java对象为空时,将null转换为"" 保存值为空的属性
    mysql -- 模糊查询的四种方法
    Mysql 查询以某个字符开头的语句
  • 原文地址:https://www.cnblogs.com/chyuanliu/p/9364147.html
Copyright © 2011-2022 走看看