Home > Database > Mysql Tutorial > body text

mysql常用命令之-用户密码修改_MySQL

WBOY
Release: 2016-06-01 13:31:44
Original
1057 people have browsed it

bitsCN.com

mysql常用命令之-用户密码修改

 

--创建用户CREATE USER 'user1'@'localhost' IDENTIFIED BY 'pass1';GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO 'user1'@'localhost';GRANT ALL ON *.* TO 'user1'@'localhost';
Copy after login

1.修改root密码

方法1:使用mysqladmin命令

--适用于记得root旧密码,修改root密码语法:mysqladmin -u用户名 -p旧密码 password 新密码例如:# mysqladmin -u root -proot password mysql--注意:如当旧密码输入错误时会报如下错误# mysqladmin -u root -proot1 password mysqlmysqladmin: connect to server at 'localhost' failederror: 'Access denied for user 'root'@'localhost' (using password: YES)'
Copy after login

方法2:直接更新user表password字段

--适用于忘记root密码,而对root密码进行重置Step 1: 修改MySQL的登录设置# vi /etc/my.cnf--windows系统是my.ini文件--在[mysqld]的段中加上一句:skip-grant-tables,如没有[mysqld]字段,可手动添加上[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockskip-name-resolveskip-grant-tablesStep 2: 重新启动mysql[root@gc ~]# service mysql restartShutting down MySQL..[确定]Starting MySQL...[确定]Step 3: 登录并修改MySQL的root密码--此时直接用mysql即可无需密码即可进入数据库了[root@gc ~]# mysqlWelcome to the MySQL monitor.  Commands end with ; or /g.Your MySQL connection id is 2Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.mysql> use mysql;Database changedmysql> update user set password=password('new_password') where user='root';Query OK, 5 rows affected (0.00 sec)Rows matched: 5  Changed: 5  Warnings: 0mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)--注意:如果没做step1,直接用mysql登录时会报如下错误[root@gc ~]# mysqlERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)Step 4: 将MySQL的登录设置修改回来再删除/etc/my.cnf文件中的skip-grant-tablesStep 5: 重新启动mysql[root@gc ~]# service mysql restartShutting down MySQL..[确定]Starting MySQL...[确定]
Copy after login

2.修改mysql其它用户密码

同样,普通用户也可以用上面的方法

--使用mysqladmin命令[root@njdyw ~]# mysqladmin -u user1 -ppass1 password pass2--直接修改数据库表[root@njdyw ~]# mysql -u user1 -ppass1 –Dmysqlmysql> update user set password=password('pass2') where user='user1';mysql> flush privileges;
Copy after login

 

 

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!