Lamp setup 20:mysql Reset root password

Source: Internet
Author: User
Tags reserved

By default, MySQL does not have a root password and can log in directly after installation:

[Email protected] ~]# Mysql-uroot

Welcome to the MySQL Monitor. Commands End With; or \g.

Your MySQL Connection ID is 9

Server version:5.1.49 MySQL Community Server (GPL)

Copyright (c), Oracle and/or its affiliates. All rights reserved.

This software comes with absolutely NO WARRANTY. This is the free software,

And you is welcome to modify and redistribute it under the GPL v2 license

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.

Mysql>

You can use the Mysqladmin tool's password option to add a password to the root user:

[Email protected] ~]# mysqladmin-uroot password ' 654321 '

After setting the password, do not enter the password will fail to login:

[Email protected] ~]# Mysql-uroot

ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no)

[Email protected] ~]# mysql-uroot-p654321

Welcome to the MySQL Monitor. Commands End With; or \g.

Your MySQL Connection ID is 9

Server version:5.1.49 MySQL Community Server (GPL)

Copyright (c), Oracle and/or its affiliates. All rights reserved.

This software comes with absolutely NO WARRANTY. This is the free software,

And you is welcome to modify and redistribute it under the GPL v2 license

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.

Mysql>

Resetting the root password requires editing the configuration file, adding a statement: skip-grant:

[Email protected] ~]# VIM/ETC/MY.CNF

......

Read_rnd_buffer_size = 4M

Myisam_sort_buffer_size = 64M

Thread_cache_size = 8

Query_cache_size= 16M

# Try number of CPU ' s*2 for thread_concurrency

Thread_concurrency = 8

Skip-grant

......

Restart MySQL

[Email protected] ~]# mysqld restart

Shutting down MySQL. success!

Starting MySQL. success!

You don't need a password to log in now

[[email protected] ~]# MySQL

Welcome to the MySQL Monitor. Commands End With; or \g.

Your MySQL Connection ID is 1

Server version:5.1.49 MySQL Community Server (GPL)

Copyright (c), Oracle and/or its affiliates. All rights reserved.

This software comes with absolutely NO WARRANTY. This is the free software,

And you is welcome to modify and redistribute it under the GPL v2 license

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.

Mysql>

Using the MySQL Library

mysql> use MySQL

Database changed

Change the password for root in the user table to aming.com

mysql> Update user Set Password=password (' 123456 ') where user= ' root ';

Query OK, 3 rows affected (0.01 sec)

Rows Matched:3 Changed:3 warnings:0

Looking at the root information in the user table, \g looks neat:

Mysql> SELECT * from user where user= ' root ' \g;

1. Row ***************************

Host:localhost

User:root

Password: *6bb4837eb74329105ee4568dda7dc67ed2ca2ad9

Select_priv:y

Insert_priv:y

Update_priv:y

Delete_priv:y

Create_priv:y

Drop_priv:y

Reload_priv:y

Shutdown_priv:y

Process_priv:y

File_priv:y

Grant_priv:y

References_priv:y

Index_priv:y

Alter_priv:y

Show_db_priv:y

Super_priv:y

Create_tmp_table_priv:y

Lock_tables_priv:y

Execute_priv:y

Repl_slave_priv:y

Repl_client_priv:y

Create_view_priv:y

Show_view_priv:y

Create_routine_priv:y

Alter_routine_priv:y

Create_user_priv:y

Event_priv:y

Trigger_priv:y

Ssl_type:

Ssl_cipher:

X509_issuer:

X509_subject:

max_questions:0

max_updates:0

max_connections:0

max_user_connections:0

......

Exit MySQL, edit the configuration file, delete the skip-grant line, restart MySQL, log in again to log in with the new password.

[Email protected] ~]# VIM/ETC/MY.CNF

[Email protected] ~]# mysqld restart

Shutting down MySQL. success!

Starting MySQL. success!

[[email protected] ~]# MySQL

ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no)

[Email protected] ~]# mysql-uroot-p123456

Welcome to the MySQL Monitor. Commands End With; or \g.

Your MySQL Connection ID is 2

Server version:5.1.49 MySQL Community Server (GPL)

Copyright (c), Oracle and/or its affiliates. All rights reserved.

This software comes with absolutely NO WARRANTY. This is the free software,

And you is welcome to modify and redistribute it under the GPL v2 license

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.

Mysql>


Lamp setup 20:mysql Reset root password

Related Article

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.