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"
    

      

  • 相关阅读:
    《基于B_S模式的教务管理系统设计与实现》论文笔记(三)
    《重修补考报名考务管理信息系统中的网络技术》论文笔记(二)
    《基于WEB的独立学院补考重修管理系统研究》论文笔记(一)
    重修安排管理系统的设计与实现 文献收集
    重修安排管理系统的设计与实现 文献收集
    《暗时间》读书笔记
    R、Python、Scala 和 Java,到底该使用哪一种大数据编程语言?
    编程和音乐真的很像吗?
    关于虚拟现实叙事方式的终极入门指南
    如何避免脆弱的代码
  • 原文地址:https://www.cnblogs.com/chyuanliu/p/9364147.html
Copyright © 2011-2022 走看看