mysql常用命令之-用户密码修改
--创建用户
CREATE USER 'user1'@'localhost' IDENTIFIED BY 'pass1';
GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO 'user1'@'localhost';
GRANT ALL ON *.* TO 'user1'@'localhost';
1.修改root密码 方法1:使用mysqladmin命令
--适用于记得root旧密码,修改root密码
语法:
mysqladmin -u用户名 -p旧密码 password 新密码
例如:
# mysqladmin -u root -proot password mysql --注意:如当旧密码输入错误时会报如下错误
# mysqladmin -u root -proot1 password mysql
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
方法2:直接更新user表password字段
--适用于忘记root密码,而对root密码进行重置
Step 1: 修改MySQL的登录设置
# vi /etc/my.cnf
--windows系统是my.ini文件
--在[mysqld]的段中加上一句:skip-grant-tables,如没有[mysqld]字段,可手动添加上
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-name-resolve
skip-grant-tables Step 2: 重新启动mysql
[root@gc ~]# service mysql restart
Shutting down MySQL..[确定]
Starting MySQL...[确定] Step 3: 登录并修改MySQL的root密码
--此时直接用mysql即可无需密码即可进入数据库了
[root@gc ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.24 MySQL Community Server (GPL) Copyright (c) 2000, 2011, 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> use mysql;
Database changed
mysql> update user set password=password('new_password') where user='root';
Query OK, 5 rows affected (0.00 sec)
Rows matched: 5 Changed: 5 Warnings: 0 mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec) --注意:如果没做step1,直接用mysql登录时会报如下错误
[root@gc ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) Step 4: 将MySQL的登录设置修改回来
再删除/etc/my.cnf文件中的skip-grant-tables Step 5: 重新启动mysql
[root@gc ~]# service mysql restart
Shutting down MySQL..[确定]
Starting MySQL...[确定]
2.修改mysql其它用户密码 同样,普通用户也可以用上面的方法
--使用mysqladmin命令
[root@njdyw ~]# mysqladmin -u user1 -ppass1 password pass2 --直接修改数据库表
[root@njdyw ~]# mysql -u user1 -ppass1 –Dmysql
mysql> update user set password=password('pass2') where user='user1';
mysql> flush privileges;
mysql常用命令之-用户密码修改的更多相关文章
- mysql设置更改root密码、mysql服务器的连接、mysql常用命令
1.设置更改root密码 查看mysql 启动与否,若没启动就运行:/usr/local/mysql56/bin/mysqlps aux |grep mysql 或 netstat -tulnp ...
- 设置更改root密码、连接mysql、mysql常用命令
6月19日任务 13.1 设置更改root密码13.2 连接mysql13.3 mysql常用命令 13.1 设置更改root密码 使用场景:例如长时间不用忘记了mysql的root密码,那么就需要去 ...
- Linux centosVMware MySQL常用操作设置更改root密码、连接mysql、mysql常用命令
一.设置更改root密码 启动mysql /usr/local/mysql/bin/mysql -uroot 更改环境变量PATH,增加mysql绝对路径 使mysql -uroot永久生效需要编辑, ...
- Mysql常用命令行大全
第一招.mysql服务的启动和停止 net stop mysql net start mysql 第二招.登陆mysql 语法如下: mysql -u用户名 -p用户密码 键入命令mysql -uro ...
- Mysql常用命令行大全——转载
转载地址:http://www.blogjava.net/supperchen/archive/2012/10/11/389340.html 第一招.mysql服务的启动和停止 net stop my ...
- MongoDB与Mysql常用命令解释
原文 本文旨在介绍MongoDB,Mysql的常用命令:将MongoDB 和传统的关系型数据库的常用命令对照起来学习,更加便于记忆和理解. MongoDB是由数据库(database/reposito ...
- Mysql 常用命令集
1.mysqlbinlog工具使用方法如下: 先使用 show binary logs 查看 在使用导出命令 mysqlbinlog -R -uroot -pxxxx -hxxx.xxx.xxx.xx ...
- MYSQL常用命令集合(转载)
文章出处:http://www.cnblogs.com/q1ng/p/4474501.html 1.导出整个数据库mysqldump -u 用户名 -p --default-character-set ...
- MYSQL常用命令集合
1.导出整个数据库 mysqldump -u 用户名 -p --default-character-set=latin1 数据库名 > 导出的文件名(数据库默认编码是latin1) mysqld ...
随机推荐
- C# WinForm应用程序降低系统内存占用方法
这里整理了一些网上关于Winform如何降低系统内存占用的资料,供参考: 1.使用性能测试工具dotTrace 3.0,它能够计算出你程序中那些代码占用内存较多2.强制垃圾回收3.创建完对象实例后,记 ...
- C++类功能扩展预留五招
第一招虚函数 通过派生类来进行功能扩展是基本的面向对象的方式,这种方式大如下: class base { public: virtual ~base(){} virtual void fun() { ...
- why does turn off button means hibernate on my win8
when I upgrated my laptop's system to win8.*,I found it's hibernate when I clicked turn off button. ...
- Linux 性能优化之 IO 子系统
本文介绍了对 Linux IO 子系统性能进行优化时需要考虑的因素,以及一些 IO 性能检测工具. 本文的大部分内容来自 IBM Redbook - Linux Performance and Tun ...
- MySQL数据库my.cnf性能参数如何调优
提供一个MySQL 5.6版本适合在1GB内存VPS上的my.cnf配置文件.配置文件可以到这里下载:: 下载my.cnf [client] port = 3306 socket = /tmp/mys ...
- SQL 常用函数及示例
--SQL 基础-->常用函数 --================================== /* 一.函数的分类 SQL函数一般分为两种 单行函数 基于单行的处理,一行产生一个结果 ...
- jsp内置对象作业2-留言簿
1.留言簿页面:liuYan.jsp <%@ page language="java" contentType="text/html; charset=UTF-8& ...
- 利用springframework+javax.mail发邮件(普通邮件、带附件邮件、HTML格式邮件)
Spring提供了发送电子邮件的支持,可以发送普通邮件.带附件邮件.HTML格式邮件,甚至还可以使用Velocity模板定制化邮件内容. 一.引入相关的库 1 2 3 4 5 6 7 8 9 10 1 ...
- 【BZOJ 3672】【UOJ #7】【NOI 2014】购票
http://www.lydsy.com/JudgeOnline/problem.php?id=3672 http://uoj.ac/problem/7 链上的情况可以用斜率优化dp.树上用斜率优化d ...
- Mysql-通过case..when实现oracle decode()函数进行多值多结果判断
oracle的decode函数使用:http://www.cnblogs.com/hwaggLee/p/5335967.html case ..when 函数使用:http://www.cnblogs ...