MySQL multiple ways to change the root password

Source: Internet
Author: User
Tags mysql login

MySQL multiple ways to change the root password


Under Navicat for MySQL directly execute SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' Newpass '); 'll be



Assuming that the compilation installation path is under/USR/LOCAL/MSYQL

To set the environment variable method:
Echo ' Export path= $PATH:/usr/local/mysql/bin ' >>/etc/profile
Source/etc/profile

So MySQL a lot of script files are under/usr/local/mysql/bin
Use these scripts without adding environment variables either it's a CD in the directory and then./a few, or the script name.
Or just use absolute paths:
To log in to the database without an initial password:
/usr/local/msyql/bin/msyql


Method 1: Use the Set password command
If you do not have an initial password and have added an environment variable, use the command MySQL login directly
If it is the way to compile the installation path to/usr/local/mysql then the absolute path/usr/local/mysql/bin/mysql such login


Mysql


mysql> SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' Newpass ');


Method 2: Use Mysqladmin (set environment variables)


mysqladmin-u root Password "Newpass"


If Root has already set a password, use the following method


mysqladmin-u root password Oldpass "Newpass"


Method 3: Edit the user table directly with update


Mysql-u Root


mysql> use MySQL;


mysql> UPDATE user SET Password = Password (' newpass ') WHERE user = ' root ';


mysql> FLUSH privileges;


This can be done when the root password is lost


Mysqld_safe--skip-grant-tables&


Mysql-u Root MySQL


mysql> UPDATE user SET Password=password ("New password") WHERE user= ' root ';


mysql> FLUSH privileges;


Or


Vim/etc/my.cnf
Find [mysqld] below to join
--skip-grant-tables
Restart database
/etc/init.d/mysqld restart
Log in to the database directly using the MySQL command
UPDATE user SET Password=password ("New password") WHERE user= ' root ';
FLUSH privileges;
\q
And then go in there and/etc/my.cnf--skip-grant-tables or delete the notes.
Then restart the database to log in with the changed password


This article is from the "12252646" blog, please be sure to keep this source http://12262646.blog.51cto.com/12252646/1947388

MySQL multiple ways to change the 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.