CentOS下设置MySQL的root密码
2015-09-24 22:58
447 查看
一、更改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:\Users\Administrator>net stop mysql MySQL 服务正在停止. MySQL 服务已成功停止。
2.打开命令行,转到mysql的bin目录下;
C:\Users\Administrator>cd C:\Program Files\MySQL\MySQL Server 5.5\bin
C:\Program Files\MySQL\MySQL Server 5.5\bin>
3.输入:mysqld -nt --skip-grant-tables 然后回车,如果没有错误信息,就行了; 注:skip-grant-tables参数用了之后,就可以跳过登录校验;
C:\Program Files\MySQL\MySQL Server 5.5\bin>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:\Users\Administrator>cd C:\Program Files\MySQL\MySQL Server 5.5\bin
C:\Program Files\MySQL\MySQL Server 5.5\bin>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;
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:\Users\Administrator>net stop mysql MySQL 服务正在停止. MySQL 服务已成功停止。
2.打开命令行,转到mysql的bin目录下;
C:\Users\Administrator>cd C:\Program Files\MySQL\MySQL Server 5.5\bin
C:\Program Files\MySQL\MySQL Server 5.5\bin>
3.输入:mysqld -nt --skip-grant-tables 然后回车,如果没有错误信息,就行了; 注:skip-grant-tables参数用了之后,就可以跳过登录校验;
C:\Program Files\MySQL\MySQL Server 5.5\bin>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:\Users\Administrator>cd C:\Program Files\MySQL\MySQL Server 5.5\bin
C:\Program Files\MySQL\MySQL Server 5.5\bin>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;
相关文章推荐
- Linux操作系统及常用基础命令深入讲解
- 马哥linux+python——2015年9月13日课程作业
- Linux终端:
- Linux的系统层次
- Linux知识框架梳理
- Linux文件操作与IO函数
- Linux下使用openssl生成证书
- linux kernel 的配置及编译
- Linux C编程学习笔记-------讲19图形界面编程
- 第 十 四 天 : 服 务 器 日 常 的 监 控 工 具
- Linux 应用程序编程基础
- linux命令后台运行
- linux驱动结构
- Linux C编程学习笔记----Fedora系统下开发环境配置
- Linux下SVN服务器自动更新文件到Web目录的方法
- Praat在CentOS 6.5中安装出现./praat /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.18' not found错误的解决办法
- Linux下MySql的登陆和管理操作
- Linux服务器--CentOS6上源码安装LAMP(实现WordPress,PhpMyAdmin)
- SuSE Linux Enterprise Server 11 SP2 安装mysql
- linux kernel learning notes