• 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"
    

      

  • 相关阅读:
    【ABAP系列】SAP ABAP OOALV 动态设置单元格可否编辑
    【HANA系列】SAP HANA使用XS和HTTP创建proxy
    【HANA系列】SAP HANA SLT在表中隐藏字段并传入HANA的方法
    【BW系列】SAP 讲讲BW/4 HANA和BW on HANA的区别
    【HANA系列】SAP HANA 2.0 SPS00 SDA(Smart Data Access)连接Hadoop
    【BW系列】SAP BW on HANA 迁移问题
    【HANA系列】SAP HANA行列转换
    【HANA系列】SAP ECLIPSE中创建ABAP项目失败原因解析
    开放-封闭原则
    单一职责原则
  • 原文地址:https://www.cnblogs.com/chyuanliu/p/9364147.html
Copyright © 2020-2023  润新知