Forget MySQL root password mysqladmin Modify password method

Source: Internet
Author: User
Keywords Web programming MySQL Tutorial
Tags change clear code community create debug echo enter password

Generally come out forget the password is a new MySQL novice friend, below we tell you how to use mysqadmin to change the password to come.
I'll take a few examples and I'm sure I'll see.
1, the original password is 123456
C:>type Mysql5.bat
@echo off
mysql-uroot-p123456-p3306
The correct format for modifying the MySQL user password is:
We use
User: root (can be replaced by another)
Password: woshiduide
To demonstrate the new password.

The code is as follows
C:>mysqladmin-uroot-p Password Woshiduide
Enter Password: Hu Jintao

So the modification succeeds.
Note the space following the password keyword

There are a lot of people who modify this:

The code is as follows
c:>mysqladmin-uroot-p password ' woshiduide '
Enter Password: Hu Jintao

c:>mysqladmin-uroot-p password ' woshiduide '
Enter Password: *********
Warning:single quotes were not trimmed from the password by your command
Line client, as you might have expected.

And this time the real code is ' Woshiduide '

The code is as follows
C:>mysql-uroot-p ' Woshiduide '
Welcome to the MySQL Monitor. Commands End With; or G.
Your MySQL Connection ID is 18
Server Version:5.1.17-beta-community-nt-debug MySQL Community Server (GPL)

Type ' help, ' or ' h ' for help. Type ' C ' to clear the buffer.

Mysql>

And beginners tend to do this:

The code is as follows
C:>mysql-uroot-pwoshiduide
ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using password:y
ES)

So very depressed, BAIDU, Google search a lot of.

I'll change the code back now.

The code is as follows
C:>mysqladmin-uroot-p ' woshiduide ' password 123456

2, there is a direct access to MySQL, and then modify the password.

The code is as follows
mysql> use MySQL
Database changed
mysql> Update user Set PASSWORD = PASSWORD (' woshiduide ') where user= ' root ' and H
ost= ' localhost ';
Query OK, 1 row affected (0.05 sec)
Rows matched:1 changed:1 warnings:0

mysql> flush Privileges;

Mysql> exit
Bye

C:>mysql-uroot-pwoshiduide
Welcome to the MySQL Monitor. Commands End With; or G.
Your MySQL Connection ID is 23
Server Version:5.1.17-beta-community-nt-debug MySQL Community Server (GPL)

Type ' help, ' or ' h ' for help. Type ' C ' to clear the buffer.

Mysql>
Query OK, 0 rows affected (0.02 sec)

3, another is to use the Set PASSWORD command to modify:

The code is as follows
C:>mysql5.bat
Enter Password: Hu Jintao
Welcome to the MySQL Monitor. Commands End With; or G.
Your MySQL Connection ID is 8
Server Version:5.1.17-beta-community-nt-debug-log MySQL Community Server (GPL)

Type ' help, ' or ' h ' for help. Type ' C ' to clear the buffer.

Mysql> set password for root@ ' localhost ' = password (' woshiduide ');
Query OK, 0 rows affected (0.02 sec)

mysql> flush Privileges;
Query OK, 0 rows affected (0.09 sec)

Mysql> exit
Bye
4, GRANT also can, but this is not introduced. Because it involves the issue of permissions.

Introduction to mysqladmin command usage in MySQL

The

is used to perform administrative operations. The syntax is:
shell>; mysqladmin [OPTIONS] command [command-option] command ...
by executing mysqladmin--help, you can get a list of the options supported by your mysqladmin version. The
currently mysqladmin supports the following commands:
Create databasename creates a new database
drop databasename Deletes a database and all its tables
Extended-status Give the server an extended status message
Flush-hosts wash off all cached hosts
Flush-logs wash all the logs
Flush-tables wash out all tables
flush-privileges load authorization table again ( Same as Reload)
Kill Id,id,... Kill MySQL thread
password new password, change old password to new password
Ping check mysqld alive
Processlist Display Service Active threads list
Reload overload authorization table
Refresh Wash off all tables and turn off and open the log file
shutdown shut down server
status give the server a short status message
variables print out available variables
version Gets the information about the server's versions
All commands can be shortened to their unique prefix. For example:
shell>; mysqladmin proc Stat
+----+-------+-----------+----+-------------+------+-------+------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------+-----------+----+-------------+------+-------+------+
| 6 | monty | localhost | | Processlist | 0 | | |
+----+-------+-----------+----+-------------+------+-------+------+
uptime:10077 threads:1 questions:9 slow queries:0 opens:6 Flush tables : 1 The
Open tables:2 Memory in use:1092k Max Memory used:1116k
mysqladmin Status command results in the following columns:
Uptime The number of seconds the MySQL server has been running Number of br> Threads active threads (customers)
Questions number of customer issues started from mysqld
Slow queries number of queries that have exceeded long_query_time seconds
Opens How many tables has the mysqld already opened
Flush tables Flush ..., refresh and reload command number
Open table number of tables opened now
Memory in use memory directly allocated by MYSQLD code (Available only if MySQL is compiled with--with-debug)
Max memory used the maximum amount of memory that is allocated directly by MYSQLD code (available only when MySQL is compiled with--with-debug)
is primarily managed to go directly to MySQL CREATE TABLE
without using the words used You can also mysqldmin create Database
./***.sql (which is an export or a written statement)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.