zoukankan      html  css  js  c++  java
  • CentOS下设置MySQL的root各种密码 总结

    一、更改mysql密码常用的三种方法 大部分情况下,一般用户没有权限更改密码,只有申请了权限或root用户才可以更改密码; 

    1.方法1:用mysqladmin 

    mysqladmin -u root password "123456";

    如果root已经设置过密码,采用如下方法 

    mysqladmin -u root password -p "123456";

    2.方法2: 用SET PASSWORD命令,不需要使用FLUSH PRIVILEGES; 

    mysql -u root -p  mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');

    3.方法3: 用UPDATE直接编辑user表 

    mysql> USE mysql;  mysql> UPDATE user SET Password = PASSWORD('123456') WHERE user='root';

    二、windows下忘记MySQL密码的处理方法 如果在Windows下忘记了MySQL的密码,可以这样做: 1.关闭正在运行的MySQL服务:net stop mysql或 在windows 任务管理器中结束 mysqld.exe 进程或在 管理工具里面的服务找到 mysql服务 ,将其停止;

    C:UsersAdministrator>net stop mysql MySQL 服务正在停止. MySQL 服务已成功停止。

    2.打开命令行,转到mysql的bin目录下;

    C:UsersAdministrator>cd C:Program FilesMySQLMySQL Server 5.5in

    C:Program FilesMySQLMySQL Server 5.5in>

    3.输入:mysqld -nt --skip-grant-tables  然后回车,如果没有错误信息,就行了; 注:skip-grant-tables参数用了之后,就可以跳过登录校验; 

    C:Program FilesMySQLMySQL Server 5.5in>mysqld -nt --skip-grant-tables 140317 13:23:11 [Warning] option 'new': boolean value 't' wasn't recognized. Set  to OFF.

    4.再打开一个命令行(因为刚才那个DOS窗口已经不能动了),同样转到mysql的bin目录下;  5.直接输入 mysql 并回车,如果成功,将出现MySQL提示符 >

    C:UsersAdministrator>cd C:Program FilesMySQLMySQL Server 5.5in

    C:Program FilesMySQLMySQL Server 5.5in>mysql Welcome to the MySQL monitor.  Commands end with ; or g. Your MySQL connection id is 1 Server version: 5.5.35 MySQL Community Server (GPL)

    Copyright (c) 2000, 2013, 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>

    6.切换到mysql表

    mysql>USE mysql;

    7.可以修改密码了:

    UPDATE user SET password=PASSWORD("123456") WHERE user="root";

    8.刷新权限,不要忘记了:

    mysql>FLUSH PRIVILEGES;

    9.退出:(退出的方法很多 有quit、exit、ctrl+c、q 等等);  10.注销或重启计算机,然后打开MySQL服务,使用用户名root和设置的新密码就可以登录了。

    三、CentOS 重设忘记的MySQL密码,可以用以下方法重设。 

    方法一、 代码  

    # /etc/init.d/mysqld stop  

    mysqld_safe --user=mysql --skip-grant-tables --skip-networking &  

    # mysql -u root mysql   

    mysql> UPDATE user SET Password=PASSWORD('输入新设的密码newpassword') where USER='root';   

    mysql> FLUSH PRIVILEGES;    mysql> quit  

    # /etc/init.d/mysqld restart   # mysql -uroot -p   

    Enter password: 输入新设的密码newpassword  mysql>   方法二、  代码   直接使用/etc/mysql/debian.cnf文件中[client]节提供的用户名和密码:  

    # mysql -udebian-sys-maint -p   

    Enter password: <输入[client]节的密码>   

    mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';   

    mysql> FLUSH PRIVILEGES;   

    mysql> quit  

    # mysql -uroot -p   

    Enter password: <输入新设的密码newpassword>   

    mysql>  

    四、支持远程访问:

    如果你想连接你的mysql的时候发生这个错误: 

    ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL server 

    解决方法:

    1. 改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"

    mysql -u root -p

    mysql>use mysql;

    mysql>update user set host = '%' where user = 'root';

    mysql>select host, user from user;

    2. 授权法。例如,你想root使用123456从任何主机连接到mysql服务器的话。

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123546' WITH GRANT OPTION;

    如果你想允许用户root从ip为192.168.1.3的主机连接到mysql服务器,并使用123456作为密码

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY '123456' WITH GRANT OPTION;

    MySQL数据库设置远程访问权限方法小结

    很多情况下我们需要远程连接mysql数据库,那么就可以参考下面的权限设置

     
    MySQL基础知识第一期,如何远程访问MySQL数据库设置权限方法总结,讨论访问单个数据库,全部数据库,指定用户访问,设置访问密码,指定访问主机。

    1,设置访问单个数据库权限

     代码如下:

    mysql>grant all privileges on test.* to 'root'@'%';

    说明:设置用户名为root,密码为空,可访问数据库test

    2,设置访问全部数据库权限

     代码如下:

    mysql>grant all privileges on *.* to 'root'@'%';

    说明:设置用户名为root,密码为空,可访问所有数据库*

    3,设置指定用户名访问权限

     代码如下:

    mysql>grant all privileges on *.* to 'liuhui'@'%';

    说明:设置指定用户名为liuhui,密码为空,可访问所有数据库*

    4,设置密码访问权限

     代码如下:

    mysql>grant all privileges on *.* to 'liuhui'@'%' IDENTIFIED BY 'liuhui';

    说明:设置指定用户名为liuhui,密码为liuhui,可访问所有数据库*

    5,设置指定可访问主机权限

     代码如下:

    mysql>grant all privileges on *.* to 'liuhui'@'10.2.1.11';

    说明:设置指定用户名为liuhui,可访问所有数据库*,只有10.2.1.11这台机器有权限访问

    还可以设置指定访问某个数据库下的某个数据表,请继续关注MySQL基础知识系列。

  • 相关阅读:
    mysql for update 高并发 死锁研究
    IntelliJ IDEA导航特性Top20
    idea工具
    图片水印处理-temp
    idea常用快捷键列表
    编写MyLayer,2 锚点,3 精灵的创建,4 zorder
    CSS学习(十六)-HSLA颜色模式
    android中LocalBroadcastManager的使用
    什么是鸭子类型(duck typing)
    线程应用的场景
  • 原文地址:https://www.cnblogs.com/imsoft/p/mysql.html
Copyright © 2011-2022 走看看